2012-08-06 54 views
0

這是我的佈局,我想通過編碼將表格行添加到表格佈局中。表格行在我的佈局中包裝內容

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

所以,你能幫我做輸出全屏?

回答

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> 
+0

非常感謝Shaiful ......這正是我想要的。它的工作很好。 – 2012-08-06 10:49:22