ConstraintLayout

0、相关文章

万字长文 - 史上最全ConstraintLayout(约束布局)使用详解

文章0:ConstraintLayout在项目中实践与总结(500赞,详细,有代码)

文章1:Android 约束布局(ConstraintLayout)详解(阅读量2w,12赞)

文章2:Android新特性介绍,ConstraintLayout完全解析(郭霖,阅读量28w)

文章3:ConstraintLayout——约束性布局学习(阅读量7k,详细)

文章4:约束布局——ConstraintLayout

文章5:Android 入门——ConstraintLayout详解以及使用替代你的常规布局

文章6:ConstraintLayout约束布局详解

文章7:我的Android开发之旅(三):ConstraintLayout的浅入

1、为什么使用ConstraintLayout

参考:文章4

在绘制复杂UI时,由于Android绘制视图是根据Z-Order机制,一层层迭代绘制,如果布局嵌套过多,UI层级过深,设备在绘制时所需的时间以及计算功耗就会过多,内存占用也就越多,由于绘制是在UI线程执行,而UI线程不能做耗时操作,所以就需要减少布局嵌套过多。

普通的LinearLayout和RelativeLayout,在绘制简单的布局时可以使用,但是在复杂的布局时,就会出现嵌套问题。而ConstraintLayout属于扁平化处理,可以按照比例约束控件位置和尺寸,因此在Android碎片化如此严重的情况下,这个特点太重要了。

ConstraintLayout官方文档

2、如何使用ConstraintLayout

参考:文章4

2.1、添加依赖

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

2.2、相对定位

app:layout_constraintLeft_toLeftOf="parent" // 当前控件与其父布局左对齐
app:layout_constraintLeft_toRightOf="parent" // 当前控件左与其父布局右对齐,
若父布局设置了width,则子控件会不可见
app:layout_constraintRight_toLeftOf="parent" // 当前控件右与其父布局左对齐,
若父布局设置了width,则子控件会不可见
app:layout_constraintRight_toRightOf="parent" // 当前控件与其父布局右对齐
app:layout_constraintTop_toTopOff="parent" // 当前控件与其父布局顶部对齐
app:layout_constraintBottom_toBottomOf="parent" // 当前控件与其父布局底部对齐
app:layout_constraintTop_toBottomOf="other" // 当前控件在other底部
app:layout_constraintBottom_toTopOf="other" // 当前控件在other顶部部
app:layout_constraintStart_toEndOf
app:layout_constraintStart_toStartOf
app:layout_constraintEnd_toStartOf
app:layout_constraintEnd_toEndOf
app:layout_constraintBaseline_toBaselineOf="other" // 当前控件与other的内容水平对齐


 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值