ConstraintLayout能够减少布局的层级并改善布局性能,能够灵活地定位和调整子View的大小,子View依靠约束关系来确定位置。在一个约束关系中,需要有一个 Source(源)以及一个 Target(目标),Source 的位置依赖于 Target,可以理解为“通过约束关系,Source 与 Target链接在了一起,Source 相对于 Target 的位置便是固定的了。
gradle配置
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta2'
一、基本属性
ConstraintLayout 最基本的属性控制有以下几个,即 layout_constraintXXX_toYYYOf 格式的属性,即将“View A”的方向 XXX 置于 “View B”的方向 YYY 。当中,View B 可以是父容器即 ConstraintLayout ,用“parent”来表示
- layout_constraintBaseline_toBaselineOf (View A 内部文字与 View B 内部文字对齐)
- layout_constraintLeft_toLeftOf (View A 与 View B 左对齐)
- layout_constraintLeft_toRightOf (View A 的左边置于 View B 的右边)
- layout_constraintRight_toLeftOf (View A 的右边置于 Vie