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

Android基础_页面布局_TableLayout(表格布局)

2015-07-28 09:08 597 查看
表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象。TableRow可以添加子控件,每添加一个为一列。

TableLayout属性:

android:collapseColumns:将TableLayout里面指定的列隐藏,若有多列需要隐藏,用逗号将需要隐藏的序列隔开即可。android:collapseColumns="1,3,4";

android:stretchColumns:设置指定的列为可伸展列,以填满剩下的多余的空白空间,若有多列需要设置,用逗号隔开。

android:shrinkColumns:设置指定的列为可收缩列,当可收缩的列太宽时内容不会内挤出屏幕,设置多列用逗号隔开。

TableRow属性:

android:layout_column:设置该控件在TableRow中指定的列。

android:layout_span:设置列占据几列的宽度。

下面放个例子:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" >

<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1" >

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_margin="5dp"
android:background="#00868B" />

<EditText
android:id="@+id/xml_showPower"
android:layout_margin="5dp"
android:enabled="false"
android:focusable="false"
android:gravity="center"
android:hint="显示电量" />

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_margin="5dp"
android:background="#00868B" />

<TextView
android:layout_width="match_parent"
android:layout_margin="5dp"
android:gravity="center"
android:text="重启、关闭服务、按键检测" />

<TableRow android:gravity="center_vertical" >
<Button
android:id="@+id/xml_restartService"
android:text="重启服务" />
<EditText
android:id="@+id/xml_key"
android:enabled="false"
android:focusable="false"
android:hint="检测按键" />
<Button
android:id="@+id/xml_closeService"
android:text="关闭服务" />
</TableRow>

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_margin="5dp"
android:background="#00868B" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="高频RFID相关测试" />

<TableRow android:gravity="center_vertical" >
<Button
android:id="@+id/xml_openHRFID"
android:text="打开模块" />
<EditText
android:id="@+id/xml_HRFIDSN"
android:enabled="false"
android:focusable="false"
android:hint="卡片序列号" />
<Button
android:id="@+id/xml_closeHRFID"
android:text="关闭模块" />
</TableRow>

<TableRow android:gravity="center_vertical" >
<Button
android:id="@+id/xml_readHData"
android:text="读数据" />
<EditText
android:id="@+id/xml_showReadHData"
android:layout_span="2"
android:focusable="false"
android:enabled="false" />
</TableRow>

<TableRow android:gravity="center_vertical" >
<Button
android:id="@+id/xml_writeHData"
android:text="写数据" />
<EditText
android:id="@+id/xml_showWriteHData"
android:layout_span="2"
android:digits="0123456789abcdefABCDEF" />
</TableRow>

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_margin="5dp"
android:background="#00868B" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:text="超高频RFID相关测试" />

<TableRow android:gravity="center_vertical">
<Button
android:id="@+id/xml_openSRFID"
android:text="打开模块"/>
<EditText
android:id="@+id/xml_SRFIDSN"
android:enabled="false"
android:focusable="false"
android:hint="卡片序列号"/>
<Button
android:id="@+id/xml_closeSRFID"
android:text="关闭模块"/>
</TableRow>

<TableRow android:gravity="center_vertical">
<Button
android:id="@+id/xml_readSRFIDStatus"
android:text="询问状态"
android:layout_span="3"/>
</TableRow>

<TableRow android:gravity="center_vertical">
<Button
android:id="@+id/xml_readSRFIDPower"
android:text="读取功率" />
<EditText
android:id="@+id/xml_showReadSRFIDPower"
android:enabled="false"
android:focusable="false"
android:layout_span="2"/>
</TableRow>

<TableRow android:gravity="center_vertical">
<Button
android:id="@+id/xml_writeSRFIDPower"
android:text="设置功率" />
<EditText
android:id="@+id/xml_showWriteSRFIDPower"
android:digits="0123456789"
android:maxLength="2"
android:layout_span="2"/>
</TableRow>

</TableLayout>

</ScrollView>

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