2010-01-19 85 views
6

我有以下的Android的TableRow RelativeLayout的問題

<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/admin_row" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal"> 
    <RelativeLayout android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="horizontal" 
        android:background="@color/silver"> 

我動態填充表,但相對佈局有色銀它只跨越錶行的約3/4。如果我把一個LinearLayout與水平方向完全跨越,但如果我改變它垂直同樣的問題發生。我需要在表格行中的相對佈局,因爲我需要這樣的東西:


詳細信息更多詳細信息。

關於獲取相對佈局跨錶行的任何想法?

回答

1

您應該將android:background="@color/silver"屬性放在TableRow上。

我在ScrollView裏有一個與LinearLayout相同的問題。

希望它能幫助,

林特

+0

我不想爲行着色。我使用它作爲調試機制來確定爲什麼我的相對佈局不會跨越整個行。 – phogel 2010-01-22 18:44:56

6

,所以我不得不暫時從本期開始移動了,但它又來了起來。重申一遍,我所看到的問題是,無論我將其設置爲寬度和高度,表格行內的相對佈局都不會跨越整行。我發現,強迫任何佈局跨越錶行完全(水平)的解決方案:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/detail_row" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
    <RelativeLayout android:layout_height="fill_parent" 
        android:layout_width="0dp" 
        android:layout_weight="1" 
        android:orientation="horizontal"> 

注意這似乎是直接違背什麼錶行Java文檔狀態:

的TableRow的子項不需要 指定XML 文件中的layout_width和 layout_height屬性。 TableRow總是強制這些值分別爲FILL_PARENT 和WRAP_CONTENT。

+1

你剛剛度過了我的一天,幫助我達到了最後期限。謝謝一堆! – zabawaba99 2012-11-29 19:10:20

12

試着在你的TableLayout標籤上設置android:stretchColumns =「0」或者android:stretchColumns =「*」。

+0

哇,這是一個完美的答案! – PCoder 2012-10-05 20:32:47