当前位置:操作系统 > 安卓/Android >>

Android 程式开发:(五)屏幕组件 —— 5.4 TableLayout表格布局

TableLayout可以把视图views组织成“行”或“列”。可以使用<TableRow>元素指定表格中的一行。每一行又可以包含一个或多个视图。每行中的每个视图组成了表格的一个元素。每列的宽度,取决于这一列中宽度最大的视图view。

观察main.xml中的代码:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent" >  
  5.   
  6.     <TableRow>  
  7.   
  8.         <TextView  
  9.             android:text="User Name:"  
  10.             android:width="120dp" />  
  11.   
  12.         <EditText  
  13.             android:id="@+id/txtUserName"  
  14.             android:width="200dp" />  
  15.     </TableRow>  
  16.   
  17.     <TableRow>  
  18.   
  19.         <TextView android:text="Password:" />  
  20.   
  21.         <EditText  
  22.             android:id="@+id/txtUserName"  
  23.             android:password="true" />  
  24.     </TableRow>  
  25.   
  26.     <TableRow>  
  27.   
  28.         <TextView />  
  29.   
  30.         <CheckBox  
  31.             android:id="@+id/chkRememberPassword"  
  32.             android:layout_width="fill_parent"  
  33.             android:layout_height="wrap_content"  
  34.             android:text="Remember Password" />  
  35.     </TableRow>  
  36.   
  37.     <TableRow>  
  38.   
  39.         <Button  
  40.             android:id="@+id/buttonSignIn"  
  41.             android:text="Log In" />  
  42.     </TableRow>  
  43.   
  44. </TableLayout>  
模拟器上的效果图:

\

以上的例子,TableLayout中有2列,4行。在“Password” TextView视图的正下方,是一个空的<TextView>元素。如果不这么做的话,“Remember Password” CheckBox就会出现在“Password”TextView视图的下面,就像这样:

\



摘自 manoel的专栏
补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,