android移动开发基础案例代码_⼈⼈都可写代码-Android零基
础编程-表格布局10
欢迎来到⼈⼈都可写代码,⼤家好,我是杨晓华,今天我们的课程内容是:Android界⾯布局中的表格布局。
1、TableLayout的概述android编程入门指南 pdf
(1)TableLayout继承了 LinearLayout,它的本质依然是线性布局管理器。每次向TableLayout中添加⼀个TableRow,该TableRow就是⼀个表格⾏,TableRow也是容器,因此它也可以不断地添加其他组件,每添加⼀个⼦组件该表格就增加⼀列。如果直接向TableLayout 中添加组件,那么这个组件将直接占⽤⼀⾏。
(2)TableRow不需要设置宽度layout_width和⾼度layoutJieight,其宽度⼀定是match_parent,,⾼度⼀定为wrap_content。
但对于TableRow中的其他控件来说,是可以设置宽度和⾼度的,但必须是 wrap_content 或者 fill_parent。
2、TableLayout的三种属性
(1)Shrinkable:如果某个列被设为Shrinkable,那么该列的所有单元格的宽度可以被收缩,以保证该表格能适应⽗容器的宽度。
(2)Stretchable:如果某个列被设为Stretchable,那么该列的所有单元格的宽度可以被拉伸,以保证组件能完全填满表格空余空间。
(3)Collapsed:如果某个列被设为Collapsed,那么该列的所有单元格会被隐藏。
3、举例说明
(1)实现的布局效果:
(2)对应的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="schemas.android/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow
android:id="@+id/tablerow1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />
</TableRow>
</TableLayout>
开头:⼈⼈都可写代码-Android零基础编程-序⾔-01
下⼀篇:⼈⼈都可写代码-Android零基础编程-相对布局11

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。