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

Android_02_表格布局

2015-10-14 12:38 573 查看
代码示例如下:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1"
>

<!--
表格布局:
每有一个TableRow子节点表示一行,该子节点的每一个子节点都表示一列
TableLayout的一级子节点默认宽都是匹配父元素
TableRow的子节点默认宽高都是包裹内容,所以其子节点的宽高都可以省略不写

android:stretchColumns="1"
表示拉伸第1列,列的索引是从0开始的

android:layout_column="1"
表示改变当前列的索引值为1
其属性提示不出来,需要手动去写

android:layout_span="2"
表示设置当前这一列占据两列的空间
其属性提示不出来,需要手动去写

关于分割线,我们一般用TextView来做:

-->
<TableRow
>
<TextView
android:layout_column="1"
android:text="open"
/>
<TextView
android:gravity="right"
android:text="Ctrl-O"
/>
</TableRow>
<TableRow >
<TextView
android:layout_column="1"
android:text="save"
/>
<TextView
android:gravity="right"
android:text="Ctrl-S"
/>
</TableRow>
<TableRow
>

<TextView
android:layout_column="1"
android:text="save AS"
/>
<TextView
android:text="Ctrl-shift-S"
/>
</TableRow>

<TextView
android:layout_height="1dp"
android:background="#000000"
/>

<TableRow

>
<TextView
android:text="X"
/>
<TextView
android:layout_span="2"
android:text="Import"
/>

</TableRow>
<TableRow

>
<TextView
android:text="X"
/>
<TextView
android:text="Export"
/>
<TextView
android:gravity="right"
android:text="Ctrl-E"
/>
</TableRow>
<TextView
android:layout_height="1dp"
android:background="#000000"
/>
<TableRow

>
<TextView
android:layout_column="1"
android:layout_span="2"
android:text="Quit"
/>

</TableRow>

</TableLayout>

实际效果如下:

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