2013-06-25 27 views
0

我想創建這樣一個佈局的所有colums:對齊所有TableRows

enter image description here

我有一個TableLayout在我的活動佈局:

 <TableLayout 
      android:id="@+id/table" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:stretchColumns="1" > 
     </TableLayout> 

然後我充氣與這個TableRow佈局:

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tablerow" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:layout_weight="1" 
     android:text="name" /> 

    <TextView 
     android:id="@+id/value" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_column="1" 
     android:layout_weight="1" 
     android:text="value" /> 

</TableRow> 

並將其添加到TableLayout。我嘗試將stretchColumns設置爲0或1,使用不同的layout_width值,無濟於事。 我需要所有TableRows的所有第一列與最廣泛的TextView一樣寬。

+0

嘗試wrap_content的寬度和你的TextView的在TableRow沒有重量 – FunkTheMonk

+0

是的,這有效。我以爲我已經嘗試過了。謝謝! – FWeigl

回答

0

它也發生在我身上!可能是圖形佈局不合適,但是當我在6個設備上運行應用程序時......它對所有人都有效! (包括三星標籤!!),所以只需運行,看看它。

+0

我在設備上運行它,第一列的寬度總是包裝TextView,它們都不相同。感謝您的輸入。 – FWeigl