安卓ConstraintLayout布局

安卓除了有6种最基本的布局线性布局(LinearLayout)、相对布局(RelativeLayout)、帧布局(FrameLayout)、网格布局(GridLayout)、绝对布局(AbsoluteLayout)、表格布局(TableLayout)外还有一些较复杂的布局,如ConstraintLayout。
1、优点
调整控件的位置和大小时更加灵活,功能更强大。
2、继承关系
和其他布局一样继承自ViewGroup。
3、新特性
相对定位:
<Button android:id="@+id/buttonA" ... />
<Button android:id="@+id/buttonB" ...
app:layout_constraintLeft_toRightOf="@+id/buttonA" />
按钮b的右对齐按钮a

  • 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 // 文本内容基准线对齐
  • layout_constraintStart_toEndOf // 起始边向尾部对齐
  • layout_constraintStart_toStartOf // 起始边向起始边对齐
  • layout_constraintEnd_toStartOf // 尾部向起始边对齐
  • layout_constraintEnd_toEndOf // 尾部向尾部对齐
    外边距:
    <android.support.constraint.ConstraintLayout ...>
    <Button android:id="@+id/button" ...
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent/>
    <android.support.constraint.ConstraintLayout/>
    空间居中效果
    倾向:
    <android.support.constraint.ConstraintLayout ...>
    <Button android:id="@+id/button" ...
    app:layout_constraintHorizontal_bias="0.3"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent/>
    <android.support.constraint.ConstraintLayout/>
    左边占0.3,右边占0.7
    可见性的表现:
    尺寸约束:
    android:minWidth 设置布局的最小宽度
    android:minHeight 设置布局的最小高度
    CHAIN:
    辅助工具:

转载于:https://blog.51cto.com/11369088/2064129

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值