【Android(安卓)开发教程】TableLayout表格布局
16lz
2021-01-25
本章节翻译自《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- <?xmlversion="1.0"encoding="utf-8"?>
- <TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TableRow>
- <TextView
- android:text="UserName:"
- android:width="120dp"/>
- <EditText
- android:id="@+id/txtUserName"
- android:width="200dp"/>
- </TableRow>
- <TableRow>
- <TextViewandroid: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="RememberPassword"/>
- </TableRow>
- <TableRow>
- <Button
- android:id="@+id/buttonSignIn"
- android:text="LogIn"/>
- </TableRow>
- </TableLayout>
以上的例子,TableLayout中有2列,4行。在“Password” TextView视图的正下方,是一个空的<TextView>元素。如果不这么做的话,“Remember Password” CheckBox就会出现在“Password”TextView视图的下面,就像这样:
更多相关文章
- android widget简单开发三之实时刷新widget
- 6.22 android计算字符高度宽度,红蓝3D图片的制作原理及NDK生成实
- GestureLibrary增加手势笔记
- android 中文api (63) —— SimpleAdapter.ViewBinder
- Android(安卓)API 中文(77)――AdapterView.OnItemSelectedListene
- Android(安卓)ViewTreeObserver简介
- android (13) Fragment使用下
- Android用RecyclerView实现动态添加本地图片
- 【转】Android的计量单位px,in,mm,pt,dp,dip,sp