android學習筆記9:TableLayout

來源:互聯網
上載者:User

上一篇:http://www.bkjia.com/kf/201112/115573.html

TableLayout即表格版面配置,也就是採用行列的方式來管理UI控制項,每一個TableRow代表一行,列的數目根據你添加的控制項的數目來確定。且可以指定每一列的展開收縮。

實現效果如下:

 

 

XML代碼如下:


<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<!-- 定義第一個表格版面配置,指定第2列允許收縮,第3列允許展開 --> 
<TableLayout android:id="@+id/TableLayout01"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content" 
    android:shrinkColumns="1" 
    android:stretchColumns="2" 
> 
<!-- 直接添加按鈕,它自己會佔一行 --> 
<Button android:id="@+id/ok1"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="獨自一行的按鈕" 
    /> 
<!-- 添加一個表格行 --> 
<TableRow> 
<!-- 為該表格行添加3個按鈕 --> 
<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 android:id="@+id/TableLayout01"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content" 
    android:collapseColumns="1" 
> 
<!-- 直接添加按鈕,它自己會佔一行 --> 
<Button android:id="@+id/ok5"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=" 獨自一行的按鈕 " 
    /> 
<!--定義一個表格行--> 
<TableRow> 
<!-- 為該表格行添加3個按鈕 --> 
<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="被隱藏的按鈕" 
    />  
<Button android:id="@+id/ok8"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="普通按鈕 3" 
    /> 
</TableRow>    
</TableLayout> 
<!-- 定義第三個表格版面配置 ,指定第2、3兩列可以被展開--> 
<TableLayout android:id="@+id/TableLayout01"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content" 
    android:stretchColumns="1,2" 
> 
<!-- 直接添加按鈕,它自己會佔一行 --> 
<Button android:id="@+id/ok9"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="獨自一行的按鈕" 
    /> 
<!--定義一個表格行--> 
<TableRow> 
<!-- 為該表格行添加3個按鈕 --> 
<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>    
<!--定義一個表格行--> 
<TableRow> 
<!-- 為該表格行添加2個按鈕 --> 
<Button android:id="@+id/ok13"  
    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>    
</TableLayout> 
</LinearLayout> 


摘自 hn307165411的專欄

聯繫我們

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