本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。

原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/


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

观察main.xml中的代码:

[java] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent">
  5. <TableRow>
  6. <TextView
  7. android:text="UserName:"
  8. android:width="120dp"/>
  9. <EditText
  10. android:id="@+id/txtUserName"
  11. android:width="200dp"/>
  12. </TableRow>
  13. <TableRow>
  14. <TextViewandroid:text="Password:"/>
  15. <EditText
  16. android:id="@+id/txtUserName"
  17. android:password="true"/>
  18. </TableRow>
  19. <TableRow>
  20. <TextView/>
  21. <CheckBox
  22. android:id="@+id/chkRememberPassword"
  23. android:layout_width="fill_parent"
  24. android:layout_height="wrap_content"
  25. android:text="RememberPassword"/>
  26. </TableRow>
  27. <TableRow>
  28. <Button
  29. android:id="@+id/buttonSignIn"
  30. android:text="LogIn"/>
  31. </TableRow>
  32. </TableLayout>
模拟器上的效果图:

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


更多相关文章

  1. android widget简单开发三之实时刷新widget
  2. 6.22 android计算字符高度宽度,红蓝3D图片的制作原理及NDK生成实
  3. GestureLibrary增加手势笔记
  4. android 中文api (63) —— SimpleAdapter.ViewBinder
  5. Android(安卓)API 中文(77)――AdapterView.OnItemSelectedListene
  6. Android(安卓)ViewTreeObserver简介
  7. android (13) Fragment使用下
  8. Android用RecyclerView实现动态添加本地图片
  9. 【转】Android的计量单位px,in,mm,pt,dp,dip,sp

随机推荐

  1. android 关于localhost和访问本机服务的
  2. android 交叉编译工具的认识
  3. android日历和时间选择器 普通选择和dial
  4. android中webview调用拨号盘
  5. Android判断是否有网络
  6. Android 判断是否是数字及数字的范围
  7. Android 获取本机唯一序列号 和可变UUID
  8. Android 文件相关总结
  9. Android Error之BufferOverflowException
  10. android studio中的错误transformClasses