属性
一个View相对另一个View的位置:
一般格式为 layout_constraintXxx_toYyyOf
Xxx或者Yyy都写四个属性左边左对齐,括号为以前的写法,可以使用,但是不建议,分别为:
- Top--------顶部或者上边
- Bottom---底部或者下边
- Start(Left)------左侧
- End(Right)-----右侧
Xxx为需要定位的View上下左右,Yyy为锚点View的上下左右
例:锚点View的id是view1,我需要设置第二个View(需要定位的View)的上在锚点View的下面,那么就是:layout_constraintTop_toBottomOf="@id/view1"
就是
常用属性如下
- layout_constraintStart_toStartOf---------左对左
- layout_constraintStart_toEndOf----------左对右
- layout_constraintTop_toTopOf------------上对上
- layout_constraintTop_toBottomOf-------上对下
- layout_constraintEnd_toEndOf-----------右对右
- layout_constraintEnd_toStartOf----------右对左
- layout_constraintBottom_toBottomOf--下对下
- layout_constraintBottom_toTopOf-------下对上
简单介绍
layout_constraintXxx_toYyyOf有两种定位方法:
- 根据父布局的上下左右定位:"parent"
- 根据某个View的上下左右定位:"@id/id"
宽度或高度设置:
这里只写高度设置,宽度设置同理:
layout_width或layout_height设置自适应(wrap_content)会根据你设置的上下左右居中
layout_width或layout_height设置0dp会根据你设置的上下左右定位宽度或高度会被写死
layout_width设置match_parent那么左右定位可以不写,写了也没啥作用,高度同理
懒得写了,推荐其他大佬写的
Android ConstraintLayout约束布局的使用_androidx.constraintlayout.widget.constraintlayout-CSDN博客