Android布局_表格版面配置TableLayout

來源:互聯網
上載者:User

標籤:

一、TableLayout概述

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

 

 

二、TableLayout的全域屬性

   1、android:collapseColumns = "1,2"      

      隱藏從0開始索引列,列直接必須ongoing逗號隔開:1,2,5

<TableLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:collapseColumns="0" >    <TableRow        android:id="@+id/tableRow1"        android:layout_width="match_parent"        android:layout_height="match_parent">        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第一個按鈕"            android:id="@+id/button" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第二個按鈕"            android:id="@+id/button2" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第三個按鈕"            android:id="@+id/button3" />    </TableRow></TableLayout>

 

  2、android:shrikColumns = "1,2"      

      收縮從0開始的索引列。當可收縮的列太寬(內容過多)不會被擠出螢幕,列直接必須用逗號隔開:1,2,5,你可以通過"*"代替收縮所有列。注意一列能同時表示收縮和展開。

<TableLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:shrinkColumns="2" >    <TableRow        android:id="@+id/tableRow1"        android:layout_width="match_parent"        android:layout_height="match_parent">        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第一個按鈕"            android:id="@+id/button" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第二個按鈕"            android:id="@+id/button2" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第三個按鈕大神快放假了凱撒的解放路卡手機的路口發生的積分卡拉斯加"            android:id="@+id/button3" />    </TableRow></TableLayout>

 

  3、android:stretchColumns = "1,2"    

    展開從0開始的索引列。以填滿剩下的多餘空白控制項,列直接必須用逗號隔開:1,2,3,可以通過"*"代替收縮所有列。注意一列能同時表示收縮和展開。

<TableLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:stretchColumns="2" >    <TableRow        android:id="@+id/tableRow1"        android:layout_width="match_parent"        android:layout_height="match_parent">        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第一個按鈕"            android:id="@+id/button" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第二個按鈕"            android:id="@+id/button2" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="第三個按鈕"            android:id="@+id/button3" />    </TableRow></TableLayout>

 

 

 

 

 

三、TableLayout的局部屬性(內部控制項所有屬性)

  1、android:layout_column = "1"       該控制項顯示在第二列

   2、android:layout_span = "2"           該控制項佔據2列

 

 

 

四、實現簡單的計算機布局

<TableLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:stretchColumns="*"    android:shrinkColumns="*">    <TextView        android:gravity="right|center"        android:layout_width="fill_parent"        android:layout_height="40"        android:text="90"        android:id="@+id/textView" />    <TableRow        android:id="@+id/tableRow1"        android:layout_width="match_parent"        android:layout_height="match_parent">        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="7"            android:id="@+id/button" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="8"            android:id="@+id/button2" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="9"            android:id="@+id/button3" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="/"            android:id="@+id/button4" />    </TableRow>    <TableRow        android:id="@+id/tableRow2"        android:layout_width="match_parent"        android:layout_height="match_parent">        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="4"            android:id="@+id/button5" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="6"            android:id="@+id/button6" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="7"            android:id="@+id/button7" />        <Button            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="*"            android:id="@+id/button8" />    </TableRow></TableLayout>

 

 

 

  

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.