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

观察main.xml中的代码:

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableRow> <TextView android:text="User Name:" android:width="120dp" /> <EditText android:id="@+id/txtUserName" android:width="200dp" /> </TableRow> <TableRow> <TextView android:text="Password:" /> <EditText android:id="@+id/txtUserName" android:password="true" /> </TableRow> <TableRow> <TextView /> <CheckBox android:id="@+id/chkRememberPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Remember Password" /> </TableRow> <TableRow> <Button android:id="@+id/buttonSignIn" android:text="Log In" /> </TableRow> </TableLayout>模拟器上的效果图:

Android 程式开发:(六)详解屏幕组件 —— 6.4TableLayout

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

Android 程式开发:(六)详解屏幕组件 —— 6.4TableLayout


相关文章:

  • 2021-09-22
  • 2021-05-21
  • 2021-06-29
  • 2021-11-30
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-08
  • 2021-05-24
  • 2021-08-22
  • 2021-09-25
  • 2021-11-23
  • 2021-06-04
相关资源
相似解决方案