TableLayout 表格布局管理器

来源:互联网 发布:淘宝账号不用了怎么办 编辑:程序博客网 时间:2024/04/29 09:52

与表格相似,以行和列的形式来管理放入其中的UI组件,在表格布局中,可以添加多个<TableRow>标记,每个<TableRow>标记占用一行。由于<TableRow>也是容器,所以还可以在此容器中添加其他组件,没添加一个组件,表格就会增加一列。列可以被隐藏,也可以被收缩或拉伸。

基本语法:

<TableLayout   xmls:android="..."

         属性列表

>

        <TableRow  属性列表> 需要添加的UI组件</TableRow>

</TableLayout>

本身特有属性:

android:collapseColumns(设置需要隐藏的列的序列号,多个序列号用","分隔)

android:shrinkColumns(设置需要收缩的列的序列号,多个序列号用","分隔)

android:stretchColumns(设置需要拉伸的列的序列号,多个序列号用","分隔)

简单实例代码:

<?xml version="1.0" encoding="utf-8"?><TableLayout android:id="@+id/tableLayout1"android:layout_width="fill_parent" android:layout_height="fill_parent"xmlns:android="http://schemas.android.com/apk/res/android"android:background="@drawable/background_a"android:gravity="center_vertical"android:stretchColumns="0,3"><!-- 第一行--><TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView/><TextView android:text="用户名" android:id="@+id/textView1" android:layout_width="wrap_content"android:textSize="24px" android:layout_height="wrap_content"/><EditText android:id="@+id/editText1" android:textSize="24px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="200px"/><TextView /></TableRow><!-- 第二行--><TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView/><TextView android:text="密码" android:id="@+id/textView2" android:textSize="24px" android:layout_width="wrap_content" android:layout_height="wrap_content"/><EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="24px" android:id="@+id/editText2" android:inputType="textPassword"/><TextView /></TableRow><!-- 第三行--><TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView/><Button android:text="登录" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"/><Button android:text="取消? android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"/><TextView /></TableRow></TableLayout>


原创粉丝点击