Android布局之表格布局TableLayout詳解
本文實(shí)例為大家分享了Android表格布局TableLayout的具體代碼,供大家參考,具體內(nèi)容如下
1.TableLayout
TableLayout表格布局模型以行列的形式管理子控件,每一行為一個(gè)TableRow的對(duì)象, 當(dāng)然也可以使一個(gè)View的對(duì)象
2.TableLayout的屬性(全局屬性)
android:collapseColumns=”1,2”
隱藏從0開始的索引列,列之間必須用逗號(hào)隔開1,2
android:shrinkColumns=”1,2”
收縮從0開始的索引列,當(dāng)可收縮的列太寬(內(nèi)容太多時(shí))不會(huì)被擠出屏幕,列之間
用逗號(hào)隔開1,2,你可以通過”*”代替收縮所有列,注意一列能同時(shí)表示收縮和拉伸
android:stretchColumns=”1,2”
拉伸從0開始的索引列,以填滿剩下的多余空白空間,列之間必須用逗號(hào)隔開,1,2,
你可以通過”*”代替收縮所有列,注意一列能同時(shí)表示收縮和拉伸
3.TableLayout的局部屬性(內(nèi)部控件所用屬性)
android:layout_column=”1” 該控件顯示在第1列
android:layout_span=”2” 該控件占據(jù)兩列
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:collapseColumns="0" android:shrinkColumns="4"> <TableRow android:id="@+id/tablerow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button1" /> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button2" /> <Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button3" /> <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button4" /> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button555555555555555555555555" /> </TableRow> </TableLayout>

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="*"> <TableRow android:id="@+id/tablerow1" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button1" /> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button2" /> <Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button3" /> </TableRow> </TableLayout>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 使用FragmentTabhost代替Tabhost
這篇文章主要介紹了Android 使用FragmentTabhost代替Tabhost的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android仿微博加載長(zhǎng)圖滾動(dòng)查看效果
這篇文章主要為大家詳細(xì)介紹了Android仿微博加載長(zhǎng)圖滾動(dòng)查看效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
輕松實(shí)現(xiàn)Android仿淘寶地區(qū)選擇功能
這篇文章主要介紹了輕松實(shí)現(xiàn)Android仿淘寶地區(qū)選擇功能的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06
RxJava+Retrofit+OkHttp實(shí)現(xiàn)多文件下載之?dāng)帱c(diǎn)續(xù)傳
本篇文章主要介紹了RxJava+Retrofit+OkHttp實(shí)現(xiàn)多文件下載之?dāng)帱c(diǎn)續(xù)傳,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11
Android布局中g(shù)ravity與layout_gravity屬性說明
這篇文章主要介紹了Android布局中g(shù)ravity與layout_gravity屬性說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
Android編程之監(jiān)聽器用法實(shí)例分析
這篇文章主要介紹了Android編程之監(jiān)聽器用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android監(jiān)聽器的功能及針對(duì)短信的監(jiān)聽與響應(yīng)操作技巧,需要的朋友可以參考下2016-01-01
Android 用RxBinding與RxJava2實(shí)現(xiàn)短信驗(yàn)證碼倒計(jì)時(shí)功能
這篇文章主要介紹了Android 用RxBinding與RxJava2實(shí)現(xiàn)短信倒計(jì)時(shí)功能示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Android studio 如何刪除項(xiàng)目 module
本篇文章主要介紹了Android studio 如何刪除項(xiàng)目module的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-05-05

