Android開發(fā)菜單布局之表格布局示例

本文實例講述了Android開發(fā)菜單布局之表格布局。分享給大家供大家參考,具體如下:

大邑縣網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,大邑縣網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為大邑縣上1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的大邑縣做網(wǎng)站的公司定做!

多用于靜態(tài)菜單頁面

xml代碼

代碼內(nèi)帶詳細解釋

<?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 個表格布局,第二列收縮第三列拉伸-->
  <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="無設(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 個表格布局,第二列隱藏-->
  <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自己會占一行"/>
    <!--添加一個表格-->
    <!--由于設(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 個表格布局,第二列和第三列拉伸-->
  <!--多行花式設(shè)計-->
  <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自己會占一行"/>
    <!--添加一個表格-->
    <!--由于設(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>

效果圖:

Android開發(fā)菜單布局之表格布局示例

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》

希望本文所述對大家Android程序設(shè)計有所幫助。

分享名稱:Android開發(fā)菜單布局之表格布局示例
本文來源:http://muchs.cn/article10/iehogo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、全網(wǎng)營銷推廣微信公眾號、外貿(mào)網(wǎng)站建設(shè)、App設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)