Android布局之TableLayout表格版面配置_Android

來源:互聯網
上載者:User

Tablelayout類以行和列的形式對控制項進行管理,每一行為一個TableRow對象,或一個View控制項。當為TableRow對象時,可在TableRow下添加子控制項,預設情況下,每個子控制項佔據一列。 當為View時,該View將獨佔一行。

三個常用的屬性

android:collapseColumns:設定需要被隱藏的列的序號

android:shrinkColumns:設定允許被收縮的列的列序號

android:stretchColumns:設定運行被展開的列的列序號

學習導圖

(1)TableLayout的相關簡介

  java的swing編程和html中經常會使用到表格,可見表格的應用開發中使用還是比較多的,同樣android也為我們提供這樣的布局方式。

(2)如何確定行數

  a:直接向TableLayout組件,直接佔一行

  b:如果想在一行添加多個組件, 就需要使用TableRow中添加

  c:TableRow中有多少個組件,這一行就會有多少列

(3)三個常用屬性(都是從零開始計數)

  Shrinkable:如果某一列被設定為Shrinkable,那麼該列的所有儲存格的寬度可以被收縮,以保證表格能適應父容器的寬度;

  Stretchable:如果某一列被設定為Stretchable,那麼該列的所有儲存格的寬度可以展開,以保證組件完全填充表格空餘空間;

  Collapsed:如果某一列被設定為Collapsed,那麼該列的所有儲存格的都會被隱藏;

(4)使用執行個體(為了示範效果沒有,所有組件都沒有設定id)

<?xml version="1.0" encoding="utf-8"?><LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical">  <!--定義第一個表格版面配置,指定第二列允許收縮,第三列展開-->  <TableLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:shrinkColumns="1"    android:stretchColumns="2">    <!-- 直接添加組件會獨佔一行-->    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="獨自佔一行"      />    <TableRow>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="收縮按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="展開按鈕"/>    </TableRow>  </TableLayout>  <!--定義第二個表格版面配置指定第二列隱藏-->  <TableLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:collapseColumns="1">    <!-- 直接添加組件會獨佔一行-->    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="獨自佔一行"      />    <TableRow>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>    </TableRow>  </TableLayout>  <!--定義第三個表格版面配置,指定第二列,第三列都可以被展開-->  <TableLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:stretchColumns="1,2">    <!-- 直接添加組件會獨佔一行-->    <Button      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:text="獨自佔一行"      />    <TableRow>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="普通按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="展開按鈕"/>      <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="展開按鈕"/>    </TableRow>  </TableLayout></LinearLayout>

以上內容是小編給大家介紹的android布局之TableLayout表格版面配置,希望大家喜歡。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.