如何在ConstraintLayout上将4个按钮分成2组来实现类似于下图的效果?
这两组按钮必须通过一些额外的填充适当地左/右对齐。

发布于 2017-07-24 23:40:44
只需将最左边和最右边的按钮约束到父级的边缘,并将内部按钮约束在外部按钮上。
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#eee">
<Button
android:id="@+id/l1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="L1"
app:layout_constraintLeft_toLeftOf="parent"/>
<Button
android:id="@+id/l2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="L2"
app:layout_constraintLeft_toRightOf="@+id/l1"/>
<Button
android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R1"
app:layout_constraintRight_toLeftOf="@+id/r2"/>
<Button
android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R2"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>

发布于 2017-07-25 00:33:41
使用widget在约束布局中分隔两组按钮。GuideLine是基于百分比的。
https://stackoverflow.com/questions/45284542
复制相似问题