Android ConstraintLayout 属性简易介绍

本文详细介绍了Android ConstraintLayout的各种属性,包括位置属性、控件对齐方式、辅助线设置、偏移百分比、宽高比控制、大小控制等。此外还提到了ConstraintLayout动画的实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android ConstraintLayout 属性简易介绍

一、位置属性

  1. app:layout_constraintLeft_toLeftOf
  2. app:layout_constraintLeft_toRightOf
  3. app:layout_constraintRight_toLeftOf
  4. app:layout_constraintRight_toLeftOf

  5. app:layout_constraintTop_toTopOf

  6. app:layout_constraintTop_toBottomOf
  7. app:layout_constraintBottom_toTopOf
  8. app:layout_constraintBottom_toBottomOf

  9. app:layout_constraintStart_toEndOf

  10. app:layout_constraintStart_toStartOf
  11. app:layout_constraintEnd_toStartOf
  12. app:layout_constraintEnd_toStartOf

二、控件与某个控件水平对齐

app:layout_constraintBaseline_toBaselineOf

三、android.support.constraint.Guideline 辅助线

android:orientation
配合
app:layout_constraintGuide_begin
app:layout_constraintGuide_end
app:layout_constraintGuide_percent
实现辅助线功能,方便看效果,,,貌似也没啥卵用

四、偏移百分比

app:layout_constraintHorizontal_bias //水平方向
app:layout_constraintVertical_bias //垂直方向

注意配合以下约束使用
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintRight_toRightOf=”parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintBottom_toBottomOf=”parent”

五、设置宽高比

app:layout_constraintDimensionRatio
使用则需要把宽(layout_width)或者高(layout_height)设置为0dp

六、大小控制

` app:layout_constraintHorizontal_weight=”1”

app:layout_constraintVertical_weight=”1”
`
1. 实现水平方向线性布局,所有的View都必须设置左右边界控制属性,而且相互控制(相邻的两个View说清楚谁在谁的左/右/上/下)
2. 实现比重大小控制,必须设置layout_width=”0dp”

七、其他

app:layout_goneMarginLeft

八、Constraint Layout 动画

ConstraintLayout通过结合ConstraintSet和TransitionManager,可方面的实现一些简单Constraint Layout动画,如果需要实现复杂动画,请了解Android Transition

//The left margin to use when the target is gone.

app:layout_goneMarginTop

//The top margin to use when the target is gone.

app:layout_goneMarginRight

//The right margin to use when the target is gone

app:layout_goneMarginBottom

//The bottom margin to use when the target is gone.

app:layout_goneMarginStart

//The start margin to use when the target is gone.

app:layout_goneMarginEnd

//The end margin to use when the target is gone.

参考链接:
http://www.jianshu.com/p/c60f787817ad

GitHub代码:
https://github.com/AriesJiang/AriesDemo/blob/master/app/src/main/java/com/niqiu/ui/ConstraintLayoutActivity.java

我的笔记系列:
https://github.com/AriesJiang/AriesDemo/blob/master/note

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值