表格行在我的布局中包含内容

时间:2012-08-06 10:28:12

标签: android android-layout android-emulator android-xml

这是我的布局,我希望通过编码将表格行添加到表格布局中。

layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bgblack"
    android:orientation="vertical" >
    <ScrollView
        android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/linearLayout1" >

    <RelativeLayout
            android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bgblack"
        android:orientation="vertical" >
    <TextView
            android:id="@+id/section_phone"
                android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/linearLayout1"
                android:background="@color/Grey"
            android:padding="2dp"
            android:text="@string/section_phone"
                android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@android:color/white"
            android:textStyle="bold" />
        <RelativeLayout
            android:id="@+id/detail_phone"
                android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/section_phone" >
                <TableLayout
                android:id="@+id/list_phone"
                    android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
            </TableLayout>
        </RelativeLayout>
        </RelativeLayout>
</ScrollView>
</RelativeLayout>

tablerow.xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <LinearLayout
        android:id="@+id/details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/detail_phone_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/Blue" />
        <TextView
            android:id="@+id/detail_phone_subtitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableRight="@drawable/ic_contact_call"
            android:padding="5dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/white" />
    </LinearLayout>
</TableRow>

但是当我看到输出表行没有全宽。它只带有包装内容。

输出

Output of layout with half

那你可以帮我全屏输出吗?

1 个答案:

答案 0 :(得分:0)

拉伸所选列将解决您的问题。看到这个链接。 TableLayout.html#attr_android:stretchColumns

<!-- The zero-based index of the columns to stretch. -->
<TableLayout
        android:id="@+id/list_phone"
        android:stretchColumns="0"  
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TableLayout>