Android布局方式之表格布局管理器(TableLayout)


在Android中,线性布局和表格布局用的是最多的。

在很多的输出操作中,往往会使用表格的形式对显示的数据进行排版,tablelayout采用表格形式对控件的布局进行管理的,在布局的管理中,要使用TableRow进行表格行的控制,之后所有的组件要在tableRow中进行增加:

如图:

 

下面我们就看看一个典型的tableLayout的布局方式:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.    <TableRow >  
  8.       <EditText  
  9.          android:id="@+id/input"  
  10.          android:layout_width="wrap_content"  
  11.          android:layout_height="wrap_content"  
  12.          android:hint="请输入查找字符"  
  13.          />  
  14.          <Button   
  15.          android:id="@+id/search"  
  16.          android:layout_width="wrap_content"  
  17.          android:layout_height="wrap_content"  
  18.          android:text="查找"  
  19.          />  
  20.     </TableRow >  
  21.     <View   
  22.     android:layout_height="2px"  
  23.     android:layout_width="fill_parent"  
  24.     android:background="#FF909032"  
  25.     />  
  26.     <TableRow >  
  27.          <TextView   
  28.          android:id="@+id/views"  
  29.          android:layout_width="wrap_content"  
  30.          android:layout_height="wrap_content"  
  31.          android:text="请选择编码"  
  32.          />  
  33.          <RadioGroup >  
  34.          <RadioButton   
  35.          android:id="@+id/radiobtn1"  
  36.          android:layout_width="wrap_content"  
  37.          android:layout_height="wrap_content"  
  38.          android:text="UTF_8"  
  39.          />  
  40.          <RadioButton   
  41.          android:id="@+id/radiobtn2"  
  42.          android:layout_width="wrap_content"  
  43.          android:layout_height="wrap_content"  
  44.          android:text="SHIF_JIS"  
  45.          />  
  46.          </RadioGroup>  
  47.     </TableRow>  
  48. </TableLayout>  
主要实现是通过TableLayout里面嵌套不同的widget来做到的。结果运行如下:


其中的一个分隔符是view来达到这种分割的现实效果的。

  • 1
  • 2
  • 下一页

相关内容