Android開發(fā)之TableLayout表格布局
表格布局模型以行列的形式管理子控件,每一行為一個(gè)TableRow的對(duì)象,當(dāng)然也可以是一個(gè)View的對(duì)象。TableRow可以添加子控件,每添加一個(gè)為一列。
TableLayout屬性:
android:collapseColumns:將TableLayout里面指定的列隱藏,若有多列需要隱藏,請(qǐng)用逗號(hào)將需要隱藏的列序號(hào)隔開。
android:stretchColumns:設(shè)置指定的列為可伸展的列,以填滿剩下的多余空白空間,若有多列需要設(shè)置為可伸展,請(qǐng)用逗號(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>
希望本文所述對(duì)大家學(xué)習(xí)Android軟件編程有所幫助。
相關(guān)文章
Android實(shí)現(xiàn)點(diǎn)贊動(dòng)畫(27)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)點(diǎn)贊動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
Android實(shí)現(xiàn)APP環(huán)境分離(利用Gradle)
有過互聯(lián)網(wǎng)軟件開發(fā)經(jīng)驗(yàn)的朋友一定對(duì)于測(cè)試環(huán)境和生產(chǎn)環(huán)境這兩個(gè)詞很是熟悉,在開發(fā)和測(cè)試階段,我們常常需要在同一個(gè)設(shè)備上同時(shí)安裝著兩套甚至多套環(huán)境的同一個(gè)應(yīng)用,便于觀察調(diào)試。所以這篇文章就來和大家分享Android利用Gradle實(shí)現(xiàn)APP環(huán)境分離的方法。2016-09-09
基于Flutter實(shí)現(xiàn)按位置大小比例布局的控件
做視頻監(jiān)控項(xiàng)目時(shí)需要需要展示多分屏,比如2x2、3x3、414等等,所以本文為大家介紹了如何基于Flutter實(shí)現(xiàn)按位置大小比例布局的控件,需要的可以參考一下2023-08-08
Android ListView 和ScroolView 出現(xiàn)onmeasure空指針的解決辦法
這篇文章主要介紹了Android ListView 和ScroolView 出現(xiàn)onmeasure空指針的解決辦法的相關(guān)資料,需要的朋友可以參考下2017-02-02
Android APK使用Debug簽名重新打包 Eclipse更改默認(rèn)Debug簽名
這篇文章主要介紹了Android APK使用Debug簽名重新打包 Eclipse更改默認(rèn)Debug簽名等內(nèi)容,需要的朋友可以參考下2015-04-04
Android 用 camera2 API 自定義相機(jī)
本文主要介紹了Android 用 camera2 API 自定義相機(jī)的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-04-04
android實(shí)現(xiàn)數(shù)獨(dú)游戲機(jī)器人
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)數(shù)獨(dú)游戲機(jī)器人,文中安裝步驟介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03

