TextView“fill_parent”未填充父级

时间:2013-09-06 14:32:39

标签: android android-layout textview android-linearlayout android-xml

我有一个简单的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

但即使我填写了fill_parent,我的TextView也没有占用所有的宽度。如何使用完整尺寸而不仅仅是内容的大小?

1 个答案:

答案 0 :(得分:7)

LinearLayoutmatch_parent属性中,让wrap_contentandroid:layout_width代替android:layout_height

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