ConstraintLayout

一、单个控件使用技巧

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" 属性
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值