首页 > 解决方案 > 如何按颜色填充网格单元格

问题描述

我需要用背景颜色填充整个单元格,但我得到了这个: 我在任何地方都使用了“match_parent”并且它什么也没给出,请帮助代码:

<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<GridLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gucciBlack"
    android:padding="3dp">


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/gucciRed"
        android:text="@string/days" />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="0"
        android:background="@color/gucciRed"
        android:text="mon" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="1"
        android:background="@color/gucciLazur"
        android:text="tue" />

 ... other checkboxes (same code) ...
</android.support.v7.widget.CardView>

标签: android

解决方案


发生这种情况是因为您的TextView宽度和高度设置为"wrap_content". 尝试将它们更改"match_parent"为 ,如下所示:

   <TextView
         android:id="@+id/textView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_column="0"
         android:layout_row="0"
         android:background="@color/gucciRed"
         android:text="@string/days" />

推荐阅读