ConstraintLayout用法笔记

英文好的可以去看官方文档: ConstraintLayout 官方文档 下面内容全部来自官方文档

相对定位

layout_constraintLeft_toLeftOf ="@id" 设置受约束控件的左边位置处于目标id控件的左边位置
layout_constraintLeft_toRightOf ="@id" 设置受约束控件的左边位置处于目标id控件的右边位置
layout_constraintRight_toLeftOf ="@id" 设置受约束控件的右边位置处于目标id控件的左边位置
layout_constraintRight_toRightOf ="@id" 设置受约束控件的右边位置处于目标id控件的右边位置
layout_constraintTop_toTopOf ="@id" 设置受约束控件的顶部位置处于目标id控件的顶部位置
layout_constraintTop_toBottomOf ="@id" 设置受约束控件的顶部位置处于目标id控件的底部位置
layout_constraintBottom_toTopOf ="@id" 设置受约束控件的底部位置处于目标id控件的顶部位置
layout_constraintBottom_toBottomOf ="@id" 设置受约束控件的底部位置处于目标id控件的底部位置
layout_constraintBaseline_toBaselineOf ="@id" 设置受约束控件的基线位置处于目标id控件的基线位置
layout_constraintStart_toEndOf ="@id" 设置受约束控件的开始(等同于左边)位置处于目标id控件的结束位置
layout_constraintStart_toStartOf ="@id" 设置受约束控件的开始位置处于目标id控件的开始位置
layout_constraintEnd_toStartOf ="@id" 设置受约束控件的结束位置处于目标id控件的开始位置
layout_constraintEnd_toEndOf ="@id" 设置受约束控件的结束位置处于目标id控件的结束位置
目标@id可以直接换成 parent 表示位于父容器的哪一边
上面各种位置对应的地方如图:
ConstraintLayout用法笔记_第1张图片
例如:想设置B在A的右侧,
ConstraintLayout用法笔记_第2张图片
需要这样做

    

app:layout_constraintLeft_toRightOf="@id/buttonA" 表示按钮B的左边在按钮A的右边, app:layout_constraintStart_toEndOf="@id/buttonA" 也表示同样的意思
另外 app:layout_constraintRight_toLeftOf=“parent” 表示控件的右边位于父容器的左边
当出现无法满足的约束的时候,就会是居中显示比如:

    

边距

layout_goneMarginStart 距离不可见控件的开始位置的距离
layout_goneMarginEnd 距离不可见控件的结束位置的距离
layout_goneMarginLeft 距离不可见控件的左边位置的距离
layout_goneMarginTop 距离不可见控件的顶部位置的距离
layout_goneMarginRight 距离不可见控件的右边位置的距离
layout_goneMarginBottom 距离不可见控件的底部位置的距离

比如:当按钮A隐藏的时候,按钮B距离A的距离是20dp,按钮A显示的时候,按钮B的距离是紧挨着A的;
设置如下 app:layout_goneMarginStart="20dp"
ConstraintLayout用法笔记_第3张图片



    
    
偏向某一侧

layout_constraintHorizontal_bias
layout_constraintVertical_bias

在这里插入图片描述
控件A不是居中而是偏向某一个边;




    
    
相对一个控件的中心店来定位

layout_constraintCircle :当前小部件引用另外一个小部件ID
layout_constraintCircleRadius :到另一个小部件中心的距离
layout_constraintCircleAngle :当前的小部件应该处于哪个角度(以度为单位,从0到360)
ConstraintLayout用法笔记_第4张图片




    

    

    


你可能感兴趣的:(ConstraintLayout用法笔记)