【轉】TableLayout(表格版面配置)

來源:互聯網
上載者:User

標籤:

轉自:http://www.cnblogs.com/zhangs1986/archive/2013/01/17/2864536.html

TableLayout(表格版面配置)

表格版面配置模型以行列的形式管理子控制項,每一行為一個TableRow的對象,當然也可以是一個View的對象。TableRow可以添加子控制項,每添加一個為一列。

TableLayout屬性:

  android:collapseColumns:將TableLayout裡面指定的列隱藏,若有多列需要隱藏,請用逗號將需要隱藏的列序號隔開。             

  android:stretchColumns:設定指定的列為可伸展的列,以填滿剩下的多餘空白空間,若有多列需要設定為可伸展,請用逗號將需要伸展的列序號隔開。                

  android:shrinkColumns:設定指定的列為可收縮的列。當可收縮的列太寬(內容過多)不會被擠出螢幕。當需要設定多列為可收縮時,將列序號用逗號隔開。

 列元素(Button)屬性:(奇怪的是button 裡面沒有android:layout_column 和android:layout_span兩個屬性,寫進去無反應,還不知道為什麼)

  android:layout_colum:設定該控制項在TableRow中指定的列

  android:layout_span:設定該控制項所跨越的列數

圖片:

代碼:

  1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  2     xmlns:tools="http://schemas.android.com/tools"  3     android:layout_width="match_parent"  4     android:layout_height="match_parent"  5     android:orientation="vertical"  6     tools:context=".AndroidTableLayoutActivity" >  7   8     <!-- 定義第一個表格,指定第2列允許收縮,第3列允許展開 -->  9  10     <TableLayout 11         android:id="@+id/tablelayout01" 12         android:layout_width="match_parent" 13         android:layout_height="wrap_content" 14         android:shrinkColumns="1" 15         android:stretchColumns="2" > 16  17         <!-- 直接添加按鈕,自己佔用一行 --> 18  19         <Button 20             android:id="@+id/btn01" 21             android:layout_width="wrap_content" 22             android:layout_height="wrap_content" 23             android:text="獨自一行" > 24         </Button> 25  26         <TableRow> 27  28             <Button 29                 android:id="@+id/btn02" 30                 android:layout_width="wrap_content" 31                 android:layout_height="wrap_content" 32                 android:text="普通" > 33             </Button> 34  35             <Button 36                 android:id="@+id/btn03" 37                 android:layout_width="wrap_content" 38                 android:layout_height="wrap_content" 39                 android:text="允許被收縮允許被收縮允許被收縮允許被收縮" > 40             </Button> 41  42             <Button 43                 android:id="@+id/btn04" 44                 android:layout_width="wrap_content" 45                 android:layout_height="wrap_content" 46                 android:text="允許被展開" > 47             </Button> 48         </TableRow> 49     </TableLayout> 50     <!-- 定義第2個表格,指定第2列隱藏 --> 51  52     <TableLayout 53         android:id="@+id/tablelayout02" 54         android:layout_width="match_parent" 55         android:layout_height="wrap_content" 56         android:collapseColumns="1" > 57  58         <TableRow> 59  60             <Button 61                 android:id="@+id/btn05" 62                 android:layout_width="wrap_content" 63                 android:layout_height="wrap_content" 64                 android:text="普通" > 65             </Button> 66  67             <Button 68                 android:id="@+id/btn06" 69                 android:layout_width="wrap_content" 70                 android:layout_height="wrap_content" 71                 android:text="被隱藏列" > 72             </Button> 73  74             <Button 75                 android:id="@+id/btn07" 76                 android:layout_width="wrap_content" 77                 android:layout_height="wrap_content" 78                 android:text="允許被展開" > 79             </Button> 80         </TableRow> 81     </TableLayout> 82     <!-- 定義第3個表格,指定第2列填滿空白--> 83  84     <TableLayout 85         android:id="@+id/tablelayout03" 86         android:layout_width="match_parent" 87         android:layout_height="wrap_content" 88         android:stretchColumns="1" 89          > 90  91         <TableRow> 92  93             <Button 94                 android:id="@+id/btn08" 95                 android:layout_width="wrap_content" 96                 android:layout_height="wrap_content" 97                 android:text="普通" > 98             </Button> 99 100             <Button101                 android:id="@+id/btn09"102                 android:layout_width="wrap_content"103                 android:layout_height="wrap_content"104                 android:text="填滿剩餘空白" >105             </Button>106         </TableRow>107     </TableLayout>108     <!-- 定義第3個表格,指定第2列橫跨2列-->109 110     <TableLayout111         android:id="@+id/tablelayout04"112         android:layout_width="match_parent"113         android:layout_height="wrap_content"114          >115 116         <TableRow>117 118             <Button119                 android:id="@+id/btn10"120                 android:layout_width="wrap_content"121                 android:layout_height="wrap_content"122                 android:text="普通" >123             </Button>124             125             <Button126                 android:id="@+id/btn11"127                 android:layout_column="2"128                 android:layout_width="wrap_content"129                 android:layout_height="wrap_content"130                 android:text="填滿剩餘空白" >131             </Button>132         </TableRow>133     </TableLayout>134 </LinearLayout>

【轉】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.