Android 表格布局TableLayout示例詳解
一、表格布局 TableLayout
表格布局TableLayout以行列的形式管理子元素,每一行是一個TableRow布局對象,當(dāng)然也可以是普通的View對象,TableRow離每放一個元素就是一列,總列數(shù)由列數(shù)最多的那一行決定。
我們看一個例子:
<?xml version=”1.0″ encoding=”utf-8″?> <TableLayout android:id=”@+id/TableLayout01″ android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:stretchColumns=”0″ xmlns:android=”http://schemas.android.com/apk/res/android”><TableRow android:layout_width=”fill_parent” android:layout_height=”20dip”> <TextView android:text=”色彩透明度測試” android:textSize=”18dip” android:layout_span=”2″ 合并兩列 android:layout_gravity=”center” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> </TextView>
在看下顯示效果圖:
其中 android:stretchColumns=”0″ 作用是讓第一列可以擴(kuò)展到所有可用空間;下面我們講一下TableLayout幾個重要的屬性:
- collapseColumns – 設(shè)置隱藏那些列,列ID從0開始,多個列的話用”,”分隔
- stretchColumns – 設(shè)置自動伸展那些列,列ID從0開始,多個列的話用”,”分隔
- shrinkColumns -設(shè)置自動收縮那些列,列ID從0開始,多個列的話用”,”分隔
可以用”*”來表示所有列,同一列可以同時設(shè)置為shrinkable和stretchable。
我們再舉一個例子來看一下:
<?xml version=”1.0″ encoding=”utf-8″?> <TableLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:stretchColumns=”1″> 第二列自動伸展<TableRow> <TextView android:layout_column=”1″ 我是第二列 android:text=”打開…” android:padding=”3dip” /> 元素內(nèi)容與邊界之間保留3dip的距離 <TextView android:text=”Ctrl-O” android:gravity=”right” android:padding=”3dip” /> </TableRow><TableRow> <TextView android:layout_column=”1″ android:text=”保存…” android:padding=”3dip” /> <TextView android:text=”Ctrl-S” android:gravity=”right” 元素本身的內(nèi)容向右對齊 android:padding=”3dip” /> </TableRow><TableRow> <TextView android:layout_column=”1″ android:text=”另存為…” android:padding=”3dip” /> <TextView android:text=”Ctrl-Shift-S” android:gravity=”right” android:padding=”3dip” /> </TableRow><View android:layout_height=”2dip” android:background=”#FF909090″ /><TableRow> <TextView android:text=”X” android:padding=”3dip” /> <TextView android:text=”導(dǎo)入…” android:padding=”3dip” /> </TableRow><TableRow> <TextView android:text=”X” android:padding=”3dip” /> <TextView android:text=”導(dǎo)出…” android:padding=”3dip” /> <TextView android:text=”Ctrl-E” android:gravity=”right” android:padding=”3dip” /> </TableRow><View android:layout_height=”2dip” android:background=”#FF909090″ /><TableRow> <TextView android:layout_column=”1″ android:text=”退出” android:padding=”3dip” /> </TableRow> </TableLayout>
下面是顯示效果圖:
我加粗顯示的地方都有解釋,大家可以留意一下。
Tip:TableRow也是一個Layout,里面的元素會水平排列,如果TableRow的父元素不是TableLayout的話,那么他會表現(xiàn)的像一個LinearLayout。
以上就是Android TableLayout 布局的資料,后續(xù)繼續(xù)補(bǔ)充相關(guān)資料,謝謝大家對本站的支持!
相關(guān)文章
Android手勢密碼view學(xué)習(xí)筆記(一)
這篇文章主要為大家詳細(xì)介紹了Android手勢密碼view的學(xué)習(xí)筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03Android自定義ScrollView實(shí)現(xiàn)阻尼回彈
這篇文章主要為大家詳細(xì)介紹了Android自定義ScrollView實(shí)現(xiàn)阻尼回彈,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04Android 進(jìn)度條自動前進(jìn)效果的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 進(jìn)度條自動前進(jìn)效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07詳解Android應(yīng)用main函數(shù)的調(diào)用
Android常識,App主線程初始化了Looper,調(diào)用prepare的地方是ActivityThread.main函數(shù)。問題來了,App的main函數(shù)在哪兒調(diào)用,下面我們來一起學(xué)習(xí)一下吧2019-06-06kotlin 定義接口并實(shí)現(xiàn)回調(diào)的例子
這篇文章主要介紹了kotlin 定義接口并實(shí)現(xiàn)回調(diào)的例子,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03