`
king_tt
  • 浏览: 2110207 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

【Android 开发教程】TableLayout表格布局

 
阅读更多

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

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


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

观察main.xml中的代码:

  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视图的下面,就像这样:


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics