ConstraintLayout使用的一些坑

android.support.constraint.ConstraintLayout

记录一下:

1. android.support.constraint.ConstraintLayout 1.1.x 以上才有百分比属性,否则报错  

app:layout_constraintWidth_percent="0.5"

app:layout_constraintHeight_percent="0.5"

2. ConstraintLayout 要使用app:layout_constraintVertical_bias="0.1" 设置的属性生效,前置条件是设置了top和bottom的约束,app:layout_constraintHorizontal_bias,要设置左右的约束,左右的约束只要设置一个就可以使用了

app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="parent"

app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"


3.ConstraintLayout如果不是根布局,布局里的子控件的约束不能设置为 "parent",要设置@+id/父控件id(ConstraintLayout)

Error:(194) error: 'percent' is incompatible with attribute xxx:layout_constraintRight_toRightOf (attr) reference|enum [parent=0].


4.constraintDimensionRatio 这个一个子控件的宽高约束比例,用法可以这样:

app:layout_constraintDimensionRatio="4:3"

app:layout_constraintDimensionRatio="h,4:3"(默认的,不设置为时为H,可以理解为竖屏时的宽高比例)

app:layout_constraintDimensionRatio="w,4:3"(这个设置时理解为横屏时的宽高比)


然后在记录一些找到常用的属性

   

layout_constraintTop_toTopOf       // 将所需视图的顶部与另一个视图的顶部对齐。 


layout_constraintTop_toBottomOf    // 将所需视图的顶部与另一个视图的底部对齐。 


layout_constraintBottom_toTopOf    // 将所需视图的底部与另一个视图的顶部对齐。 


layout_constraintBottom_toBottomOf // 将所需视图的底部与另一个视图的底部对齐。 


layout_constraintLeft_toTopOf      // 将所需视图的左侧与另一个视图的顶部对齐。 


layout_constraintLeft_toBottomOf   // 将所需视图的左侧与另一个视图的底部对齐。 


layout_constraintLeft_toLeftOf     // 将所需视图的左边与另一个视图的左边对齐。 


layout_constraintLeft_toRightOf    // 将所需视图的左边与另一个视图的右边对齐。 


layout_constraintRight_toTopOf     // 将所需视图的右对齐到另一个视图的顶部。


layout_constraintRight_toBottomOf  // 将所需视图的右对齐到另一个的底部。


layout_constraintRight_toLeftOf    // 将所需视图的右边与另一个视图的左边对齐。


layout_constraintRight_toRightOf   // 将所需视图的右边与另一个视图的右边对齐。



  • 6
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值