Android開發之TableLayout表格版面配置_Android

來源:互聯網
上載者:User

表格版面配置模型以行列的形式管理子控制項,每一行為一個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:設定該控制項所跨越的列數。

圖片:

代碼:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".AndroidTableLayoutActivity" >      <!-- 定義第一個表格,指定第2列允許收縮,第3列允許展開 -->     <TableLayout     android:id="@+id/tablelayout01"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:shrinkColumns="1"     android:stretchColumns="2" >      <!-- 直接添加按鈕,自己佔用一行 -->      <Button       android:id="@+id/btn01"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:text="獨自一行" >     </Button>      <TableRow>        <Button         android:id="@+id/btn02"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="普通" >       </Button>        <Button         android:id="@+id/btn03"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="允許被收縮允許被收縮允許被收縮允許被收縮" >       </Button>        <Button         android:id="@+id/btn04"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="允許被展開" >       </Button>     </TableRow>   </TableLayout>   <!-- 定義第2個表格,指定第2列隱藏 -->    <TableLayout     android:id="@+id/tablelayout02"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:collapseColumns="1" >      <TableRow>        <Button         android:id="@+id/btn05"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="普通" >       </Button>        <Button         android:id="@+id/btn06"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="被隱藏列" >       </Button>        <Button         android:id="@+id/btn07"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="允許被展開" >       </Button>    </TableRow>   </TableLayout>   <!-- 定義第3個表格,指定第2列填滿空白-->    <TableLayout     android:id="@+id/tablelayout03"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:stretchColumns="1"      >      <TableRow>        <Button         android:id="@+id/btn08"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="普通" >      </Button>        <Button         android:id="@+id/btn09"         android:layout_width="wrap_content"         android:layout_height="wrap_content"        android:text="填滿剩餘空白" >      </Button>     </TableRow>   </TableLayout>  <!-- 定義第3個表格,指定第2列橫跨2列-->    <TableLayout     android:id="@+id/tablelayout04"     android:layout_width="match_parent"     android:layout_height="wrap_content"     >      <TableRow>       <Button         android:id="@+id/btn10"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="普通" >       </Button>              <Button         android:id="@+id/btn11"        android:layout_column="2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="填滿剩餘空白" >       </Button>    </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.