Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将约束图拆分为具有不同背景的子部分_Android_Android Constraintlayout - Fatal编程技术网

Android 将约束图拆分为具有不同背景的子部分

Android 将约束图拆分为具有不同背景的子部分,android,android-constraintlayout,Android,Android Constraintlayout,这是一个包含四个约束布局的约束布局,我将在其中放置各种视图,如按钮等 有没有一种方法可以在不需要将更多布局嵌套到父布局中的情况下对约束布局的各个区域的背景色进行着色?尝试使用以下代码片段- 根据需要更改背景颜色 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.androi

这是一个包含四个约束布局的约束布局,我将在其中放置各种视图,如按钮等

有没有一种方法可以在不需要将更多布局嵌套到父布局中的情况下对约束布局的各个区域的背景色进行着色?

尝试使用以下代码片段- 根据需要更改背景颜色

<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>

应用可绘制的背景怎么样?很好,XML设计风格使用了约束布局,使布局变得更简单