Android布局之TableLayout表格布局
Tablelayout類以行和列的形式對(duì)控件進(jìn)行管理,每一行為一個(gè)TableRow對(duì)象,或一個(gè)View控件。當(dāng)為TableRow對(duì)象時(shí),可在TableRow下添加子控件,默認(rèn)情況下,每個(gè)子控件占據(jù)一列。 當(dāng)為View時(shí),該View將獨(dú)占一行。
三個(gè)常用的屬性
android:collapseColumns:設(shè)置需要被隱藏的列的序號(hào)
android:shrinkColumns:設(shè)置允許被收縮的列的列序號(hào)
android:stretchColumns:設(shè)置運(yùn)行被拉伸的列的列序號(hào)
學(xué)習(xí)導(dǎo)圖

(1)TableLayout的相關(guān)簡介
java的swing編程和html中經(jīng)常會(huì)使用到表格,可見表格的應(yīng)用開發(fā)中使用還是比較多的,同樣android也為我們提供這樣的布局方式。
(2)如何確定行數(shù)
a:直接向TableLayout組件,直接占一行
b:如果想在一行添加多個(gè)組件, 就需要使用TableRow中添加
c:TableRow中有多少個(gè)組件,這一行就會(huì)有多少列
(3)三個(gè)常用屬性(都是從零開始計(jì)數(shù))
Shrinkable:如果某一列被設(shè)置為Shrinkable,那么該列的所有單元格的寬度可以被收縮,以保證表格能適應(yīng)父容器的寬度;
Stretchable:如果某一列被設(shè)置為Stretchable,那么該列的所有單元格的寬度可以拉伸,以保證組件完全填充表格空余空間;
Collapsed:如果某一列被設(shè)置為Collapsed,那么該列的所有單元格的都會(huì)被隱藏;
(4)使用實(shí)例(為了演示效果沒有,所有組件都沒有設(shè)置id)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--定義第一個(gè)表格布局,指定第二列允許收縮,第三列拉伸-->
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="2">
<!-- 直接添加組件會(huì)獨(dú)占一行-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="獨(dú)自占一行"
/>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按鈕"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收縮按鈕"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸按鈕"/>
</TableRow>
</TableLayout>
<!--定義第二個(gè)表格布局指定第二列隱藏-->
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:collapseColumns="1">
<!-- 直接添加組件會(huì)獨(dú)占一行-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="獨(dú)自占一行"
/>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按鈕"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按鈕"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按鈕"/>
</TableRow>
</TableLayout>
<!--定義第三個(gè)表格布局,指定第二列,第三列都可以被拉伸-->
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2">
<!-- 直接添加組件會(huì)獨(dú)占一行-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="獨(dú)自占一行"
/>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按鈕"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸按鈕"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸按鈕"/>
</TableRow>
</TableLayout>
</LinearLayout>
以上內(nèi)容是小編給大家介紹的android布局之TableLayout表格布局,希望大家喜歡。
相關(guān)文章
Android時(shí)間日期拾取器學(xué)習(xí)使用(DatePicker、TimePicker)
這篇文章主要為大家詳細(xì)介紹了Android提供的DatePicker日期拾取器和TimePicker時(shí)間拾取器的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
Android加載對(duì)話框同時(shí)異步執(zhí)行實(shí)現(xiàn)方法
Android中通過子線程連接網(wǎng)絡(luò)獲取資料,同時(shí)顯示加載進(jìn)度對(duì)話框給用戶的操作2012-11-11
在Android中使用Anntation來代替ENUM的方法
本篇文章主要介紹了在Android中使用Anntation來代替ENUM的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02
Android 判斷SIM卡屬于哪個(gè)移動(dòng)運(yùn)營商的實(shí)現(xiàn)代碼
有時(shí)候我們需要在Android中獲取本機(jī)網(wǎng)絡(luò)提供商呢,這里簡單分享下,方便需要的朋友2013-05-05
android中TabHost的圖標(biāo)(48×48)和文字疊加解決方法
開發(fā)過程中,有時(shí)候圖標(biāo)稍微大點(diǎn),比如48×48的時(shí)候,文字就會(huì)和圖標(biāo)疊加起來,遇到這種問題我們?cè)撛鯓犹幚砟兀勘疚膶⒃敿?xì)介紹希望對(duì)你有所幫助2013-01-01
更新至Android Studio4.1后發(fā)現(xiàn)as打不開的解決方法(原因分析)
這篇文章主要介紹了更新至Android Studio4.1后發(fā)現(xiàn)as打不開的解決方案,本文給大家分享問題所在原因給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
Android RecyclerView實(shí)現(xiàn)吸頂動(dòng)態(tài)效果流程分析
RecyclerView是Android一個(gè)更強(qiáng)大的控件,其不僅可以實(shí)現(xiàn)和ListView同樣的效果,還有優(yōu)化了ListView中的各種不足。其可以實(shí)現(xiàn)數(shù)據(jù)縱向滾動(dòng),也可以實(shí)現(xiàn)橫向滾動(dòng)(ListView做不到橫向滾動(dòng))。接下來講解RecyclerView的用法2022-12-12
Flutter Image實(shí)現(xiàn)圖片加載
這篇文章主要為大家詳細(xì)介紹了Flutter Image實(shí)現(xiàn)圖片加載,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
Android 開發(fā)中Volley詳解及實(shí)例
這篇文章主要介紹了Android 開發(fā)中Volley詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-04-04

