(轉)Android ConstraintLayout的一下功能

醉過才知酒濃發表於2018-12-05

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   // 將所需檢視的右邊與另一個檢視的右邊對齊。

原文地址

相關文章