服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android开发菜单布局之表格布局示例

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

2022-10-13 14:49水中鱼之1999 Android

这篇文章主要介绍了Android开发菜单布局之表格布局,结合具体实例形式分析了Android菜单布局中表格布局的相关行列排版与设置操作技巧,需要的朋友可以参考下

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

多用于静态菜单页面

xml代码

代码内带详细解释

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?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开发菜单布局之表格布局示例

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

原文链接:https://blog.csdn.net/qq_43377749/article/details/83756665

延伸 · 阅读

精彩推荐