Android布局管理器(表格版面配置)

來源:互聯網
上載者:User

標籤:

表格版面配置有TableLayout所代表,TableLayout繼承了LinearLayout,因此他的本質依然是LinearLayout。

表格版面配置採用行、列的形式來進行管理,在使用的時候不需要聲明多少行、多少列,而是通過添加TableRow、其他組件來控製表格的行數和列數。

每次向TableLayout添加一個TableRow,該TableRow就是一個表格行,同時TableRow也是容器,可以在其中不斷的添加其他的組件,每添加一個子組件,該表格的列就增加一列

 

在表格版面配置管理器中,可以為儲存格設定如下三種行為方式

  1. Shrinkable:如果某一列被設定為Shrinkable,那麼該列的所有儲存格的寬度可以被收縮,以保證該表格能適應父容器的寬度
  2. Stretchable:如果某一列被設定為Stretchable,那麼該列的所有儲存格的寬度可以被展開,以保證組件能全部填滿表格空餘控制項
  3. Collapsed:如果某個列被設定為該屬性,那麼該列的所有儲存格都會被隱藏

因為TableLayout繼承了LinearLayout類,因此除了支援LinearLayout的全部屬性外還支援下面的三個屬性

XML屬性

方法

說明

android:collapseColumns

setColumnCollapsed(int,boolean)

設定需要被隱藏的列的序號,多個使用都逗號隔開

android:shrinkColumns

setShrinkAllColumns(boolean)

設定允許被收縮的列的序號,多個使用逗號隔開

android:stretchColumns

setStretchAllColumns(boolean)

設定允許被展開的列的序號,多個使用逗號隔開

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical"    tools:context="com.example.tablelayout.MainActivity" >       <!-- 第一個TableLayout,指定二列允許收縮,三列允許展開 -->    <TableLayout         android:id="@+id/tableLayout_one"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:shrinkColumns="1"        android:stretchColumns="3">                <Button             android:id="@+id/ok1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="獨自一行的按鈕"/>        <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>        <!-- 第二個TableLayout,指定二列允隱藏-->    <TableLayout         android:id="@+id/tableLayout_two"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:collapseColumns="2">                <Button             android:id="@+id/ok5"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="獨自一行的按鈕"/>        <TableRow>            <Button                 android:id="@+id/ok6"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="普通按鈕"/>            <Button                 android:id="@+id/ok7"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="收縮按鈕"/>            <Button                 android:id="@+id/ok8"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="隱藏按鈕"/>       </TableRow>      </TableLayout>        <!-- 第三個TableLayout,指定二列允許展開,三列允許展開 -->    <TableLayout         android:id="@+id/tableLayout_three"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:shrinkColumns="1,2">                <Button             android:id="@+id/ok9"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="獨自一行的按鈕"/>        <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/ok12"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="展開按鈕"/>       </TableRow>    </TableLayout></LinearLayout>

Android布局管理器(表格版面配置)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.