如何更改包含textviews

时间:2016-03-04 18:26:48

标签: android android-layout

我正在进行这个项目,我有一个包含两个TextView的LinearLayout。我使用android:background =“@ color / ...”设置了LinearLayout的背景颜色,但这恰当适用于textviews结束的地方。如果它在屏幕中间结束,那么颜色将停在那里,其余部分显示为白色。 我不明白。我彻底搜索无济于事。 请大家帮帮我这是我的布局文件。

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

问候。

2 个答案:

答案 0 :(得分: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的宽度设置为wrap_content。 将其更改为match_parent。

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

   ....
</LinearLayout>