约束布局简单使用

要在项目中使用 ConstraintLayout,我们需要在 build.gradle 中添加依赖(新版 AndroidStudio 会默认添加):

 implementation 'com.android.support.constraint:constraint-layout:1.1.3'

创建布局
=其实都知道 约束布局 根布局就用 ConstraintLayout:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.constraint.ConstraintLayout>
--------------------- 

添加约束
就是在Palette中添加一个button ,添加完后效果:
约束布局简单使用
约束布局简单使用
报错就按 相当于彩灯
约束布局简单使用

基线约数
约束布局简单使用

Chains
Chains(链)是一种特定的约束,一个链包含了多个视图,它允许链中的视图共享空间,并控制可用空间在它们之间如何分配。该效果与 LinearLayout 的 Weiget 类似,但是链的作用远远超过它。

我们要是想创建一个链,那么首先就需要创建多个视图控件,然后再选择是创建「水平链」还是「垂直链」。
让我们从三个视图中创建一个「水平链」:

这是水平链
约束布局简单使用
垂直链

约束布局简单使用