2011-05-31 61 views
0

作爲標題的含義,我希望我的tablelayout能夠均勻分配每列的寬度,並且每列的子項都位於列的中心。但是,也設置android:stretchColumns="*",在每列內拉伸子。Android - 如何在不擴展子項的情況下擴展Tablelayout的列

黑客入侵此問題的任何想法?

使用水平的LinearLayout模仿tablerow的是可以接受的,但我也有不知道如何獲得的LinearLayout均勻地安排其子女:(

請幫助, 在此先感謝。

回答

0

沒有破解需要。:-) 只需將孩子的layout_width設置爲wrap_content而不是fill_parent,或設置爲固定值。將layout_gravity設置爲center或center_horizo​​ntal。

編輯:添加代碼。

試試這個:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:shrinkColumns="*" android:stretchColumns="*"> 
    <TableRow> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:gravity="center" 
       /> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:gravity="center" 
       /> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:gravity="center" 
       /> 
    </TableRow> 
</TableLayout> 
+0

它似乎爲我工作,查看詳細的任何例子嗎? – user718146 2011-05-31 14:01:22

+0

它對我有用。 :-)我用代碼更新了我的答案。 – DKIT 2011-06-01 08:45:11

+0

感謝您的回覆,我很抱歉,我仍然無法使用它,使用Button小部件而不是Textview :( – user718146 2011-06-01 11:16:32

相關問題