【Android】ConstraintLayout---约束布局

属性

一个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有两种定位方法:

  1. 根据父布局的上下左右定位:"parent"
  2. 根据某个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博客

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值