2013-03-01 80 views
0

所以,我通過膨脹佈局文件從代碼創建TableLayout。我試圖讓第一行跨越兩列,每一行都包含兩個TextView:key和value。問題是這個值可能會很長,所以我在TableLayout xml中設置android:stretchColumns,android:shrinkColumns。現在鍵列和值列看起來很好,但首先跨越,標題是更大的屏幕大小。Android,在TableLayout中設置列大小

現在我的檔案情況是這樣的:

tale_row.xml:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingTop="5dp" 
    android:paddingBottom="5dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" > 
     <TextView 
      android:id="@+id/key" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/gray" 
      android:textStyle="bold" 
      android:layout_marginRight="10dp" /> 
     <TextView 
      android:id="@+id/value" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@android:color/black" />" 
</TableRow> 

header_row.xml:

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

    <TextView 
     android:id="@+id/header" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_span="2" 
     style="@style/group_separator_style" 
     android:layout_marginBottom="5dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" /> 

</TableRow> 

table.xml:

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

任何想法,什麼coul d是原因嗎?將屬性clipChildrenclipToPadding設置爲true並沒有幫助。

+0

使用layout_width在標題單元格 – njzk2 2013-03-01 08:40:58

+0

=「match_parent」可惜的是,它並沒有幫助 – Seraphis 2013-03-01 19:54:04

回答

0

它看起來像設置android:stretchColumns="1"android:shrinkColumns="1"解決了這個問題