這2組constraint屬性最好成對出現,不要app:layout_constraintLeft_toRightOf app:layout_constraintEnd_toEndOf=“parent” 這樣搭配使用將得不到你所期望的效果
app:layout_constraintLeft_toRightOf="@+id/iv_test2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@id/iv_test2"
app:layout_constraintEnd_toEndOf="parent"
Dimensions constraints 巧用0dp
三種方式:
使用確定的dp,如48dp。
WRAP_CONTENT, 根據控件自身大小計算得出。
0dp
, 意思是 MATCH_CONSTRAINT除去間距的大小,MATCH_PARENT
在ConstraintLayout是不支持的。
Chains
<Button
android:id="@+id/button_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
app:layout_constraintHorizontal_chainStyle="packed" // packed/spread_inside//spread三種模式平分空隙方式
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button_b"
tools:layout_editor_absoluteY="0dp" />
<Button
android:id="@+id/button_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
app:layout_constraintLeft_toRightOf="@+id/button_a"
app:layout_constraintRight_toLeftOf="@+id/button_c"
tools:layout_editor_absoluteY="0dp" />
<Button
android:id="@+id/button_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
app:layout_constraintLeft_toRightOf="@+id/button_b"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="0dp" />