標籤: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)