TextView"fill_parent"未填充父级

5 android textview android-layout 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>
Run Code Online (Sandbox Code Playgroud)

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

Sho*_*uri 7

使外部LinearLayout具有match_parent而不是wrap_content属性android:layout_widthandroid: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" >
Run Code Online (Sandbox Code Playgroud)

  • 两者都相同,但自从API 8以来,'fill_parent`已被折旧. (2认同)