Android開發(fā)菜單布局之表格布局示例
本文實(shí)例講述了Android開發(fā)菜單布局之表格布局。分享給大家供大家參考,具體如下:
多用于靜態(tài)菜單頁(yè)面
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 對(duì)應(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="無(wú)設(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="無(wú)設(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="無(wú)設(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="無(wú)設(shè)置 按鈕"/> </TableRow> </TableLayout> </LinearLayout>
效果圖:
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android Mms之:對(duì)話與聯(lián)系人關(guān)聯(lián)的總結(jié)詳解
本篇文章是對(duì)Android中對(duì)話與聯(lián)系人的關(guān)聯(lián)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05andriod開發(fā)之Activity的渲染機(jī)制
本文給大家分享的是在andriod開發(fā)中經(jīng)常需要用到的Activity的渲染機(jī)制的詳細(xì)說(shuō)明,主要是通過(guò)實(shí)例給大家講解Activity是如何畫到屏幕上的,希望大家能夠喜歡2018-03-03Android studio配置國(guó)內(nèi)鏡像源的實(shí)現(xiàn)
這篇文章主要介紹了Android studio配置國(guó)內(nèi)鏡像源的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Android編程實(shí)現(xiàn)調(diào)用系統(tǒng)圖庫(kù)與裁剪圖片功能
這篇文章主要介紹了Android編程實(shí)現(xiàn)調(diào)用系統(tǒng)圖庫(kù)與裁剪圖片功能,結(jié)合實(shí)例形式分析了Android針對(duì)圖形的旋轉(zhuǎn)與剪切等具體操作技巧,需要的朋友可以參考下2017-01-01Android打開淘寶客戶端(手淘)效果及實(shí)現(xiàn)代碼
這篇文章主要介紹了Android打開淘寶客戶端(手淘)效果及實(shí)現(xiàn)代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-04-04Android 實(shí)現(xiàn)永久性開啟adb 的root權(quán)限
這篇文章主要介紹了Android 實(shí)現(xiàn)永久性開啟adb 的root權(quán)限,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03