【发布时间】:2017-02-08 16:34:19
【问题描述】:
我在 ConstraintLayout 中添加了 3 个按钮。我添加了一个按钮来禁用或启用这些按钮。
如果我使用的是普通的 LinearLayout。我可以将所有按钮放在一个线性布局中并启用或禁用该特定布局。
但我正在使用 ConstraintLayout。所以我需要禁用或启用所有这些按钮,我相信在 ConstraintLayout 中一定有一种方法可以对不同的视图进行分组。
请指导我如何在 ConstriantLayout 中对视图进行分组
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
android:layout_marginStart="8dp"
app:layout_constraintLeft_toRightOf="@+id/button"
android:layout_marginLeft="8dp"
app:layout_constraintTop_toTopOf="@+id/button" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
app:layout_constraintTop_toTopOf="@+id/button2"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginStart="8dp"
app:layout_constraintLeft_toRightOf="@+id/button2"
android:layout_marginLeft="8dp" />
【问题讨论】:
-
看看,也许Chains能帮到你:developer.android.com/reference/android/support/constraint/…
-
setGroupVisibility(mLayout, group, Group.VISIBLE) ; stackoverflow.com/questions/47865436/…
标签: android performance android-layout android-linearlayout android-constraintlayout