2016-03-04 44 views
1

我有我正在处理的这个项目,并且我有一个包含两个TextView的LinearLayout。我已经使用android:background =“@color/...”设置了LinearLayout的背景颜色,但此适用仅适用于textviews结束的位置。如果它在屏幕中间结束,则颜色停在那里,其余的颜色显示为白色。 我不明白。我彻底搜索无济于事。 请大家帮帮我。这是我的布局文件。如何更改android中包含文本视图的整个线性布局的背景颜色

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/gold"> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/gold" 
    android:paddingBottom="10dp" 
    android:paddingLeft="15dp" 
    android:paddingTop="10dp" 
    android:textSize="20sp" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/gold" 
    android:paddingLeft="15dp" 
    android:paddingRight="10dp" 
    android:textSize="15sp" /> 

</LinearLayout> 

问候。

回答

3

您的LinearLayout可能只使用wrap_content。如果你想在全屏幕是彩色的,你的LinearLayout必须延伸到使用全屏幕:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/my_color> 

</LinearLayout> 

如果你的LinearLayout是不是在你的布局根元素,然后将背景设置为根元素,确保它对宽度和高度都有match_parent。

+1

我的线性布局是根元素,我已经设置了布局的高度和宽度以匹配父级,但它仍然没有工作。 –

+0

如果您的LinearLayout用作ListView的单元布局?如果是这样,请在Listview中设置背景,而不是单元格本身。 – Francesc

+0

非常感谢。刚刚解决它。 上帝保佑。 –

0

我认为......主LinearLayout的宽度设置为wrap_content。 将其更改为match_parent。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/your_color" 
    android:orientation="vertical"> 

    .... 
</LinearLayout> 
+0

我试过了,但似乎没有帮助。我只是在原始文章中添加了布局文件。感谢您的日常支持。 –

+0

将textview的高度更改为wrap_content –

+0

尝试过但同样的事情。值得一提的是,这些textview使用来自数据库和数据的数据填充。该列表使用和自定义列表适配器显示。这部分工作。我只需要将颜色从白色改为金色。 感谢您的日常支持。 –

相关问题