Android開發(fā)之TableLayout表格布局
表格布局模型以行列的形式管理子控件,每一行為一個(gè)TableRow的對象,當(dāng)然也可以是一個(gè)View的對象。TableRow可以添加子控件,每添加一個(gè)為一列。
TableLayout屬性:
android:collapseColumns:將TableLayout里面指定的列隱藏,若有多列需要隱藏,請用逗號(hào)將需要隱藏的列序號(hào)隔開。
android:stretchColumns:設(shè)置指定的列為可伸展的列,以填滿剩下的多余空白空間,若有多列需要設(shè)置為可伸展,請用逗號(hào)將需要伸展的列序號(hào)隔開。
android:shrinkColumns:設(shè)置指定的列為可收縮的列。當(dāng)可收縮的列太寬(內(nèi)容過多)不會(huì)被擠出屏幕。當(dāng)需要設(shè)置多列為可收縮時(shí),將列序號(hào)用逗號(hào)隔開。
列元素(Button)屬性:(奇怪的是button 里面沒有android:layout_column 和android:layout_span兩個(gè)屬性,寫進(jìn)去無反應(yīng),還不知道為什么)
android:layout_colum:設(shè)置該控件在TableRow中指定的列。
android:layout_span:設(shè)置該控件所跨越的列數(shù)。
圖片:
代碼:
<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" > <!-- 定義第一個(gè)表格,指定第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="獨(dú)自一行" > </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個(gè)表格,指定第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個(gè)表格,指定第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個(gè)表格,指定第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>
希望本文所述對大家學(xué)習(xí)Android軟件編程有所幫助。
相關(guān)文章
Android加載loading對話框的功能及實(shí)例代碼(不退出沉浸式效果)
這篇文章主要介紹了Android加載loading對話框的功能及實(shí)例代碼,不退出沉浸式效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-12-12Android協(xié)程的7個(gè)重要知識(shí)點(diǎn)匯總
在現(xiàn)代Android應(yīng)用開發(fā)中,協(xié)程(Coroutine)已經(jīng)成為一種不可或缺的技術(shù),它不僅簡化了異步編程,還提供了許多強(qiáng)大的工具和功能,可以在高階場景中發(fā)揮出色的表現(xiàn),本文將深入探討Coroutine重要知識(shí)點(diǎn),幫助開發(fā)者更好地利用Coroutine來構(gòu)建高效的Android應(yīng)用2023-09-09基于Flutter實(shí)現(xiàn)多邊形和多角星組件
開發(fā)中,免不了會(huì)用到多邊形、多角星等圖案,比較常用的多邊形比如雷達(dá)圖、多角星比如評(píng)價(jià)星級(jí)的五角星等,本文章就使用Flutter繪制封裝一個(gè)這樣的組件,需要的可以參考一下2022-05-05基于Flutter實(shí)現(xiàn)手勢密碼加密與解鎖功能
這篇文章主要介紹了如何利用Flutter實(shí)現(xiàn)手勢密碼的加密與解鎖,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04Android側(cè)滑菜單之DrawerLayout用法詳解
今天小編就為大家分享一篇關(guān)于Android側(cè)滑菜單之DrawerLayout用法詳解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03