2012-08-09 50 views
0

我在Android中創建應用程序,爲此我需要將屏幕劃分爲統一的行和列以填充整個屏幕。Android TableLayout控件,具有統一的行/列大小

我知道如何在HTML和WPF(和標準的GDI +)中做到這一點,但我無法在Android中找到合適的控件。

我只限於Android 3.2,所以我不能使用GridLayout,它看起來像它可以做我想做的。一旦我有了這個'table/grid'控件,我希望能夠將Buttons,TextViews等放入單元格中,並指出它們是否跨越多列或多行。

我一直在試驗TableLayout控件,但我似乎無法獲得統一大小的列/行。

我也在運行時建立這個網格。

有沒有這樣的控制,這將允許這?

謝謝, 豐富。

回答

0

我已經通過創建一個派生自ViewGroup的新類來實現這一點,它以正確的方式展示了我的「視圖」。這工作得很好,雖然我在對齊子視圖中的文本時遇到了一些麻煩。

0

至少在列寬,可以連續設置每個視圖的重量:

<TableRow> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
    </TableRow> 

    <TableRow> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
    </TableRow> 

如果你把一個砝碼放在以及這可能也行,但我從來沒有測試那。

+0

我已經試着用TableLayout,但你似乎無法跨越行或列..我想我會寫我自己的自定義控件。 – 2012-08-10 11:07:24