2012-08-09 52 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