constraintLayout备忘

2017-12-14  本文已影响84人  o动感超人o
1. 相对位置
layout_constraintLeft_toLeftOf
layout_constraintLeft_toRightOf
layout_constraintRight_toLeftOf
layout_constraintRight_toRightOf
layout_constraintTop_toTopOf
layout_constraintTop_toBottomOf
layout_constraintBottom_toTopOf
layout_constraintBottom_toBottomOf
layout_constraintBaseline_toBaselineOf
layout_constraintStart_toEndOf
layout_constraintStart_toStartOf
layout_constraintEnd_toStartOf
layout_constraintEnd_toEndOf

以layout_constraintLeft_toLeftOf 为例,其中 layout_ 部分是固定格式,主要的信息包含在下面两部分:
constraintXXX:指定当前控件需要设置约束的属性部分。如 constraintLeft 表示对当前控件的 左边 进行约束设置。
toXXXOf:其指定的内容是作为当前控件设置约束需要依赖的控件或父容器(可以理解为设置约束的参照物)。并通过 XXX 指定被依赖对象用于参考的属性。如 toLeftOf="parent" :表示当前控件相对于父容器的左边进行约束设置。

2. 边距
3. 居中
4. 偏移

layout_constraintHorizontal_bias // 水平偏移
layout_constraintVertical_bias // 垂直偏移

5. 可见性

可见性这个属性大家应该很熟悉,但是约束布局的可见性属性和其它布局相比,存在以下区别:

6. 尺寸

几种设置方式:

MATH_CONSTRAINT

设置为百分比模式的属性:

app:layout_constraintWidth_default="percent"
app:layout_constraintHeight_default="percent"
app:layout_constrainedWidth=”true|false”     
app:layout_constrainedHeight=”true|false”
7. 比例

控件可以定义两个尺寸之间的比例,目前支持宽高比。
前提条件是至少有一个尺寸设置为0dp,然后通过 layout_constraintDimentionRatio 属性设置宽高比。设置方式有以下几种:

如果宽高都设置为0dp,也可以用ratio设置。这种情况下控件会在满足比例
约束的条件下,尽可能填满父布局。

8. 链

链这个概念是约束布局新提出的,它提供了在一个维度(水平或者垂直),管理一组控件的方式。

9. Guideline

可以理解为布局辅助线,用于布局辅助,不在设备上显示。
有垂直和水平两个方向(android:orientation=“vertical/horizontal”)

有三种放置Guideline的方式:

参考:http://www.qingpingshan.com/rjbc/az/359115.html

上一篇 下一篇

猜你喜欢

热点阅读