Android開發(fā)菜單布局之表格布局示例
本文實(shí)例講述了Android開發(fā)菜單布局之表格布局。分享給大家供大家參考,具體如下:
多用于靜態(tài)菜單頁面
xml代碼
代碼內(nèi)帶詳細(xì)解釋
<?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 對應(yīng) 1,2,3列-->
<!--定義第 1 個(gè)表格布局,第二列收縮第三列拉伸-->
<TableLayout
android:id="@+id/TableLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="2">
<!--第一行不使用TableRow自己會(huì)占一行-->
<Button
android:id="@+id/ok1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一行不使用TableRow自己會(huì)占一行"/>
<!--添加一個(gè)表格-->
<TableRow>
<Button
android:id="@+id/ok2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="無設(shè)置 按鈕"/>
<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 個(gè)表格布局,第二列隱藏-->
<TableLayout
android:id="@+id/TableLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:collapseColumns="1">
<!--第一行不使用TableRow自己會(huì)占一行-->
<Button
android:id="@+id/ok5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一行不使用TableRow自己會(huì)占一行"/>
<!--添加一個(gè)表格-->
<!--由于設(shè)置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 個(gè)表格布局,第二列和第三列拉伸-->
<!--多行花式設(shè)計(jì)-->
<TableLayout
android:id="@+id/TableLayout03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2">
<!--第一行不使用TableRow自己會(huì)占一行-->
<Button
android:id="@+id/ok9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一行不使用TableRow自己會(huì)占一行"/>
<!--添加一個(gè)表格-->
<!--由于設(shè)置collapseColumns="1"故第二列隱藏-->
<TableRow>
<Button
android:id="@+id/ok10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="無設(shè)置 按鈕"/>
<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="無設(shè)置 按鈕"/>
<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="無設(shè)置 按鈕"/>
</TableRow>
</TableLayout>
</LinearLayout>
效果圖:

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android利用Espresso進(jìn)行UI自動(dòng)化測試的方法詳解
因?yàn)槲沂歉鉧ndroid開發(fā)的,所以被分到了自動(dòng)化測試小組,所以了解了一些UI自動(dòng)化測試。下面這篇文章主要給大家介紹了關(guān)于Android利用Espresso進(jìn)行UI自動(dòng)化測試的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-12-12
Flutter中數(shù)據(jù)存儲的四種方式小結(jié)
在 Flutter 中,存儲是指用于本地和遠(yuǎn)程存儲和管理數(shù)據(jù)的機(jī)制,本給大家介紹了Flutter中不同存儲選項(xiàng)的概述和示例,通過代碼示例講解的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2023-11-11
android上實(shí)現(xiàn)0.5px線條的原理分析
這篇文章主要介紹了android上實(shí)現(xiàn)0.5px線條的原理分析,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
Android 處理 View 重復(fù)點(diǎn)擊的多種方法
這篇文章主要介紹了Android 處理 View 重復(fù)點(diǎn)擊的多種方法,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03

