您的位置:首页 > 移动开发 > Android开发

Android 布局管理器 之 TableLayout

2011-04-11 10:55 309 查看
2 表格布局 TableLayout

TableLayout类以行和列的形式管理控件,每行为一个TableRow对象,也可以为一个View对象,当为View对象时,该对象将很跨改行所有列。

可以设置列为以下属性

Shrinkable:该列的宽度可以收缩,以使表格能适应其父容器大小

Stretchable:该列宽度可以拉伸,……

Collapsed:该列被隐藏

属性名称对应方法描述
android:collapseColumnssetCollapsed(int,boolean)列好从0开始
android:shrinkColumssetShrinkColumns(boolean)
android:stretchablesetStretchable(boolean)
table_layout.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/white" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/tv01" android:text="我是单独的一行。。。。"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="@drawable/darkgray" android:layout_margin="4px" />
</TableLayout>
<TableLayout android:id="@+id/TableLayout02"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:stretchColumns="0"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/tv02" android:text="我是被拉伸的一行"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/white" android:layout_margin="4px" />
<TextView android:id="@+id/tv03" android:text="我的内容少"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/white" android:layout_margin="4px" />
</TableRow>
</TableLayout>
<TableLayout android:id="@+id/TableLayout03"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:shrinkColumns="0" xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/tv04" android:text="我是被压缩的一行被压缩的一行"
android:background="@drawable/white" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_margin="4px" />
<TextView android:id="@+id/tv05" android:text="我的内容非常多内容非常多内容非常多"
android:background="@drawable/white" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_margin="4px" />
</TableRow>

</TableLayout>
</LinearLayout>




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: