安卓布局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   // 将所需视图的右边与另一个视图的右边对齐。

posted @ 2018-12-17 15:22  huangyan1022  阅读(1106)  评论(0编辑  收藏  举报