前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android开发菜单布局之表格布局示例

Android开发菜单布局之表格布局示例

作者头像
砸漏
发布2020-11-05 10:15:11
7570
发布2020-11-05 10:15:11
举报
文章被收录于专栏:恩蓝脚本

本文实例讲述了Android开发菜单布局之表格布局。分享给大家供大家参考,具体如下:

多用于静态菜单页面

xml代码

代码内带详细解释

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"? 
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
<!--分别以0,1,2 对应 1,2,3列-- 
<!--定义第 1 个表格布局,第二列收缩第三列拉伸-- 
<TableLayout
android:id="@+id/TableLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="2" 
<!--第一行不使用TableRow自己会占一行-- 
<Button
android:id="@+id/ok1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一行不使用TableRow自己会占一行"/ 
<!--添加一个表格-- 
<TableRow 
<Button
android:id="@+id/ok2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="无设置 按钮"/ 
<Button
android:id="@+id/ok3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收缩的 按钮"/ 
<Button
android:id="@+id/ok4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的 按钮"/ 
</TableRow 
</TableLayout 
<!--定义第 2 个表格布局,第二列隐藏-- 
<TableLayout
android:id="@+id/TableLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:collapseColumns="1" 
<!--第一行不使用TableRow自己会占一行-- 
<Button
android:id="@+id/ok5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一行不使用TableRow自己会占一行"/ 
<!--添加一个表格-- 
<!--由于设置collapseColumns="1"故第二列隐藏-- 
<TableRow 
<Button
android:id="@+id/ok6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"/ 
<Button
android:id="@+id/ok7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"/ 
<Button
android:id="@+id/ok8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮3"/ 
</TableRow 
</TableLayout 
<!--定义第 3 个表格布局,第二列和第三列拉伸-- 
<!--多行花式设计-- 
<TableLayout
android:id="@+id/TableLayout03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2" 
<!--第一行不使用TableRow自己会占一行-- 
<Button
android:id="@+id/ok9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一行不使用TableRow自己会占一行"/ 
<!--添加一个表格-- 
<!--由于设置collapseColumns="1"故第二列隐藏-- 
<TableRow 
<Button
android:id="@+id/ok10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="无设置 按钮"/ 
<Button
android:id="@+id/ok11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的 按钮"/ 
<Button
android:id="@+id/ok14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的 按钮"/ 
</TableRow 
<!--第二行单列-- 
<TableRow 
<Button
android:id="@+id/ok15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="无设置 按钮"/ 
<Button
android:id="@+id/ok16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的 按钮"/ 
</TableRow 
<TableRow 
<Button
android:id="@+id/ok17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="无设置 按钮"/ 
</TableRow 
</TableLayout 
</LinearLayout 

效果图:

希望本文所述对大家Android程序设计有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档