Разделите ConstraintLayout на части с другим фоном - PullRequest
0 голосов
/ 27 февраля 2019

Это макет ограничения , содержащий четыре макета ограничения , в которые я помещу различные виды, такие как кнопки и т. П.

enter image description here

Есть ли способ подкрасить цвет фона отдельных областей макета ограничения без необходимости вложения большего количества макетов в родительский?

1 Ответ

0 голосов
/ 27 февраля 2019

Попробуйте с этим фрагментом - измените цвет фона, как вы хотите.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">

    <android.support.constraint.Guideline
        android:id="@+id/guideline_ver"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent=".5" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline_hor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent=".5" />

    <View
        android:id="@+id/topLeft"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_margin="4dp"
        android:background="#E02222"
        app:layout_constraintBottom_toTopOf="@+id/guideline_hor"
        app:layout_constraintDimensionRatio="h,1:1"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent=".5"
        app:layout_constraintRight_toLeftOf="@+id/guideline_ver" />

    <View
        android:id="@+id/topRight"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_margin="4dp"
        android:background="#411010"
        app:layout_constraintBottom_toTopOf="@+id/guideline_hor"
        app:layout_constraintDimensionRatio="h,1:1"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent=".5"
        app:layout_constraintLeft_toRightOf="@+id/guideline_ver" />

    <View
        android:id="@+id/bottomLeft"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_margin="4dp"
        android:background="#165B92"
        app:layout_constraintDimensionRatio="h,1:1"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent=".5"
        app:layout_constraintRight_toLeftOf="@+id/guideline_ver"
        app:layout_constraintTop_toBottomOf="@+id/guideline_hor" />

    <View
        android:id="@+id/bottomRight"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_margin="4dp"
        android:background="#680C5F"
        app:layout_constraintDimensionRatio="h,1:1"
        app:layout_constraintHeight_default="percent"
        app:layout_constraintHeight_percent=".5"
        app:layout_constraintLeft_toRightOf="@+id/guideline_ver"
        app:layout_constraintTop_toBottomOf="@+id/guideline_hor" />

</android.support.constraint.ConstraintLayout>

Вывод будет выглядеть следующим образом -

enter image description here

...