如何通过颜色填充网格单元格

时间:2018-05-22 16:32:10

标签: android

我需要用背景颜色填充整个单元格,但我得到this: 我在任何地方都使用了“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>

2 个答案:

答案 0 :(得分:0)

这是因为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" />

答案 1 :(得分:0)

TextView,而不是background您应该使用textColor

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/gucciRed"
    android:text="@string/days" />
相关问题