Android的學習第六章(布局一TableLayout)

來源:互聯網
上載者:User

標籤:cti   shrink   match   XML   column   png   str   amp   main   

今天我們來簡單的說一下Android不置中的TableLayout布局(表格版面配置)

  表格版面配置的意思就是將我們的布局看做為一個表格,主要用於對控制項進行整齊排列

  我們看一個簡單的案例

  

<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="match_parent"    tools:context="com.example.activitylife.MainActivity"    android:stretchColumns="*">    <TableRow         android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="一"            android:gravity="center"            android:background="@android:color/holo_blue_dark"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="二"            android:gravity="center"            android:background="@android:color/holo_green_dark"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="三"            android:gravity="center"            android:background="@android:color/holo_blue_dark"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="四"            android:gravity="center"            android:background="@android:color/holo_green_dark"/>            </TableRow>    </TableLayout>

    

這裡我們可以看到一個屬性android:stretchColumns

  這裡我們要知道TableLayout中的幾個屬性

  android:stretchColumns    設定可伸展的列。該列可以向行方向伸展,最多可佔據一整行。

  android:shrinkColumns     設定可收縮的列。當該列子控制項的內容太多,已經擠滿所在行,那麼該子控制項的內容將往列方向顯示。

  android:collapseColumns 設定要隱藏的列。

看完這些我們來看一下使用TableLayout可以做的簡單的案例吧:

  

<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="match_parent"    tools:context="com.example.activitylife.MainActivity"    android:stretchColumns="*">                    <TextView        android:layout_width="match_parent"        android:layout_height="100dp"        android:background="@android:color/holo_blue_bright"        android:textSize="30dp"        android:text="0"        android:gravity="right|center"/>        <TableRow         android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="1">        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="1"/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="2"/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="3"/>                <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="+"/>            </TableRow>        <TableRow         android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="1">        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="4"/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="5"/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="6"/>                <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="-"/>            </TableRow>        <TableRow         android:layout_width="match_parent"       android:layout_height="match_parent"       android:layout_weight="1">        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="7"/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="8"/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="9"/>                <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="*"/>            </TableRow>        <TableRow         android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="1">        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="0"/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="."/>        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="/"/>                <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="="/>            </TableRow>        <TableRow         android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="1">        <Button            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="="            android:layout_span="4"/>                    </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.