android布局空间居中,Android布局之ConstraintLayout

1.简介

ConstraintLayout是一个ViewGroup,翻译为约束布局,约束布局的出现主要是为了解决布局嵌套过深的情况,自android studio2.3开始,新建布局文件默认根ViewGroup就是它

2.基本属性

2.1 相对定位

例如TextView2需要放在TextView1后方,可以使用app:layout_constraintStart_toEndOf

dffadcdf5380

Start_toEndOf

android:id="@+id/txt1"

android:text="Text1"/>

android:id="@+id/txt2"

android:text="Text2"

app:layout_constraintStart_toEndOf="@id/txt1"/>

相似的属性有:

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:对TextView有效,基线对齐

layout_constraintStart_toEndOf

layout_constraintStart_toStartOf

layout_constraintEnd_toStartOf

layout_constraintEnd_toEndOf

如果是依赖父布局的话可以使用parent

app:layout_constraintStart_toEndOf="parent"

2.2间距margins

margin和其它布局方式一样,支持的属性有:

android:layout_marginStart

android:layout_marginEnd

android:layout_marginLeft

android:layout_marginTop

android:layout_marginRight

android:layout_marginBottom

但是ConstraintLayout多了一种间距goneMargin,用来指定当依赖的控件visibility为gone时的间距,此属性当且仅当依赖控件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值