一、单个控件使用技巧
1、单个控件位于父布局居中
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
2、单个控件位于父布局左上角
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
3、单个控件位于父布局右上角
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
4、单个控件位于父布局左下角
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
5、 单个控件位于父布局右下角
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
6、单个控件位于父布局垂直居中
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
7、单个控件位于父布局水平居中
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
二、多个控件使用技巧
1、当多个控件形成 链式结构的时候,使用chainStyle 方式控制多个控件
分为水平链式 和 垂直链式
比如 当两个控件采用
id为:tv_title 属性为 app:layout_constraintRight_toLeftOf="@+id/tv_appconfig"
id为:tv_appconfig 属性为 app:layout_constraintLeft_toRightOf="@+id/tv_title"
这样就形成了左右链式,再使用app:layout_constraintHorizontal_chainStyle="packed"
就可以形成链式各种情况。
(1)、packed 代表两个控件被绑定在一起,同时居中
(2)、spread代表两个控件间隔均分
(3)、spread_inside 代表两个控件位于两端
2、为了让 margin生效
需使用
app:layout_constrainedWidth = "true" 属性