TextView不会填充父宽度

时间:2014-07-03 08:10:50

标签: android css

我有一个表格布局,有两行。

Textview的宽度不会填充Table行的整个宽度,但它填充高度就好了。

表格行的大小正确,填充高度的一半和整个宽度。

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

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

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

    </TableRow>

    <TableRow
        android:layout_weight="1"
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TableRow>

</TableLayout>

2 个答案:

答案 0 :(得分:8)

添加到您的textview

  

机器人:layout_weight = “1”

答案 1 :(得分:1)

试试这个:

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

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

</TableRow>

<TableRow
    android:layout_weight="1"
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</TableRow>

或将布局尺寸更改为fill_parent

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