Android ConstraintLayout 布局

就个人使用 ConstraintLayout 布局经验,逐步记录

一、基本属性

app:layout_constraintTop_toBottomOf="@+id/xxx"

   这里 top 和 bottom 指当前布局的 top 对齐id为xxx的布局的 bottom

更换其他方位可以达到不同的控制效果,其中有 top、bottom、start、end 分别对应上下左右

二、失效

有的时候发现写了约束布局也没有效果,是其中有一个原因是设置了  

match_parent

如果宽度设置了 match_parent 那么左右约束会失效

如果高度设置了 match_parent 那么上下约束会失效

例如:

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_store"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

这样设置了约束也没有用,只会在最上面

 

三、角度定位

app:layout_constraintCircle="@+id/iv_title"
app:layout_constraintCircleAngle="120"
app:layout_constraintCircleRadius="150dp"

app:layout_constraintCircle 是参照布局

app:layout_constraintCircleAngle 是角度(以钟形在12点方向为基准)

app:layout_constraintCircleRadius 是直径,距离参照

 

四、Group 整合控件

<android.support.constraint.Group
    android:id="@+id/group_vip"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dp_60"
    android:layout_margin="@dimen/dp_10"
    app:layout_constraintTop_toBottomOf="@+id/iv_title"
    app:constraint_referenced_ids="iv_vip,tv_vip,tv_vip_state,tv_vip_hot"/>

通过 app:constraint_referenced_ids 整合相关控件,统一控制

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值