2012-03-21 72 views
1

我有三列,我想垂直對齊。列的數據使用對象檢索,然後使用layoutflator顯示。使用自定義適配器/ layoutinflator時,垂直對齊textview列

目前列已遍佈各地。我希望讓他們完美對齊。我正在使用文本視圖,但我開始懷疑我是否不應該使用某種表格佈局。

enter image description here

下面是XML:

機器人:ID = 「@ + ID/table_layout」 的xmlns:機器人=「http://schemas.android.com/apk/ RES /機器人」 機器人:layout_width = 「FILL_PARENT」 機器人:layout_height = 「FILL_PARENT」 >

<ListView 
    android:id="@android:id/list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"   
    android:layout_weight="1" 
/> 

<TableRow  android:id="@+id/row_multi_row" 
> 

<TextView 
    android:id="@+id/item1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"    android:textAppearance="?android:attr/textAppearanceLarge"    
    android:padding="3dip"  android:layout_weight="1" 
/> 

<TextView 
    android:id="@+id/item2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"   android:textAppearance="?android:attr/textAppearanceLarge"    
    android:padding="3dip"   android:layout_weight="1"  
/> 

<TextView 
    android:id="@+id/item3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"        android:textAppearance="?android:attr/textAppearanceLarge"    
    android:padding="3dip"  android:layout_weight="1"  
/>  

</TableRow> 
    </TableLayout> 
+0

文本的意見沒有被設置爲'fill_parent',從而爲他們的需要,他們將永遠只能拿那麼多房間。 – Matthias 2012-03-21 11:50:11

回答

0

將所有textview寬度和製表符行寬設置爲填充父級並使用layout_weight =「1」。它將工作

1

enter image description here試試這個:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/row_multi_row" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:weightSum="1"> 

<TextView 
    android:id="@+id/item1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.34" 
    android:padding="3dip" 
    android:text="asdasd" 
    android:gravity="center" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/item2" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.34" 
    android:padding="3dip" 
    android:gravity="center" 
    android:text="adasd" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/item3" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.32" 
    android:padding="3dip" 
    android:gravity="center" 
    android:text="asdasdad" 
    android:textAppearance="?android:attr/textAppearanceLarge" />