当前位置:K88软件开发文章中心编程语言APP编程Android01 → 文章内容

2.2.3 TableLayout(表格布局)

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-12 6:25:02

text="three" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="four" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="five" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="文本XX" /> </TableRow> </TableLayout>运行截图:从图中我们可以看到two这个按钮被挤压成条条状,这个就是收缩,为了保证表格能适应父容器的宽度!至于另外两个属性就不讲解了,用法和HTML相同!有兴趣的可以研究下! 5.使用实例使用TableLayout来完成简单的登录界面,运行效果图如下:流程解析:①调用gravity属性,设置为center_vertical,让布局里面的组件在竖直方向上居中②将TableLayout中的第一和第四列设置为可拉伸③在每个TableRow中添加两个TextView,用于拉伸填满该行,这样可以让表格水平居中android:stretchColumns="0,3" 设置为0.3,是为了让两边都充满,那么中间部分就可以居中了详细代码如下:<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/TableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:stretchColumns="0,3" android:gravity="center_vertical" android:background="#66FF66" > <TableRow> <TextView /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名:"/> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="150dp"/> <TextView /> </TableRow> <TableRow> <TextView /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密 码:" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="150dp" /> <TextView /> </TableRow> <TableRow> <TextView /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登陆"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="退出"/> <TextView /> </TableRow> </TableLayout>6.发现的问题相信大家在使用这个这TableLayout的TableRow的时候会遇到这个警告:当然,程序还是可以运行的,不过或许你是强迫症患者,看到黄色感叹号你就不爽的话!而解决这个警告的方法也是很奇葩的:只要你的TableLayout里面有2个或以上的TableRow就可以了!本节小结:好的,关于Android的第三个布局:TableLayout就到这里~无非就是五个属性的使用而已,实际开发表格布局我们用的不多,知道简单的用法就可以了!

上一页  [1] [2] 


2.2.3 TableLayout(表格布局)