Android TabWidget底部顯示效果
TabHost控件默認(rèn)使用LinearLayout包裹TabWidget和FrameLayout,布局文件如下:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > </FrameLayout> </LinearLayout> </TabHost>
這樣TabWidget顯示在頂部,如果想把TabWidget放到底部有三種方式。
方式一:將TabHost中默認(rèn)的LinearLayout換成RelativeLayout,并給TabWidget添加Android:layout_alignParentBottom="true"
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > </FrameLayout> </RelativeLayout> </TabHost>
方式二:
1、將LinearLayout中TabWidget和FrameLayout交換位置
2、設(shè)置FrameLayout的屬性:android:layout_weight="1" android:layout_height="0dp"
<TabHost xmlns:android="<a target=_blank rel="external nofollow" >http://schemas.android.com/apk/res/android</a>" android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" ></p><p> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > </FrameLayout> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> </TabWidget> </LinearLayout> </TabHost>
方式三:
1、將TabWidget移動(dòng)到LinearLayout標(biāo)簽以下
2、在FrameLayout中加入屬性:android:layout_gravity="top"
3、在TabWidget中加入屬性:android:layout_gravity="bottom"
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="top" > </FrameLayout> </LinearLayout> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom"> </TabWidget> </TabHost>
以上三種方式在Android4.2下測(cè)試通過(guò)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android基于widget組件實(shí)現(xiàn)物體移動(dòng)/控件拖動(dòng)功能示例
- Android UI組件AppWidget控件入門(mén)詳解
- Android Widget 桌面組件開(kāi)發(fā)介紹
- Android桌面組件App Widget完整案例
- Android桌面組件App Widget用法入門(mén)教程
- Android開(kāi)發(fā)之AppWidget詳解
- Android控件AppWidgetProvider使用方法詳解
- Android小掛件(APP Widgets)設(shè)計(jì)指導(dǎo)
- 在Android中創(chuàng)建widge組件的步驟
相關(guān)文章
eclipse搭建android開(kāi)發(fā)環(huán)境詳細(xì)步驟
本文主要介紹了eclipse搭建android開(kāi)發(fā)環(huán)境詳細(xì)步驟,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-03-03
Android RatingBar星星評(píng)分控件實(shí)例代碼
本文通過(guò)實(shí)例代碼給大家介紹了Android RatingBar星星評(píng)分控件,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2017-06-06
Android實(shí)現(xiàn)讀寫(xiě)JSON數(shù)據(jù)的方法
這篇文章主要介紹了Android實(shí)現(xiàn)讀寫(xiě)JSON數(shù)據(jù)的方法,以完整實(shí)例形式分析了Android解析及生成json數(shù)據(jù)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
Android實(shí)現(xiàn)五子棋游戲(局域網(wǎng)版)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)局域網(wǎng)版的五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android實(shí)現(xiàn)開(kāi)機(jī)自動(dòng)啟動(dòng)Service或app的方法
這篇文章主要介紹了Android實(shí)現(xiàn)開(kāi)機(jī)自動(dòng)啟動(dòng)Service或app的方法,結(jié)合實(shí)例形式分析了Android開(kāi)機(jī)自啟動(dòng)程序的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-07-07
Android如何禁止向EditText控件中輸入內(nèi)容詳解
EditText是接受用戶(hù)輸入信息的最重要控件。下面這篇文章主要給大家介紹了關(guān)于Android如何禁止向EditText控件中輸入內(nèi)容的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-09-09
Android仿支付寶笑臉?biāo)⑿录虞d動(dòng)畫(huà)的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android仿支付寶笑臉?biāo)⑿录虞d動(dòng)畫(huà)的實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2016-11-11
Android WebView自定義長(zhǎng)按選擇實(shí)現(xiàn)收藏/分享選中文本功能
這篇文章主要介紹了Android WebView自定義長(zhǎng)按選擇實(shí)現(xiàn)收藏/分享選中文本功能,需要的朋友可以參考下2017-06-06
Android自定義控件實(shí)現(xiàn)方向盤(pán)效果
這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)方向盤(pán)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04
使用ViewPager實(shí)現(xiàn)android軟件使用向?qū)Чδ軐?shí)現(xiàn)步驟
現(xiàn)在的大部分android軟件,都是使用說(shuō)明,就是第一次使用該軟件時(shí),會(huì)出現(xiàn)向?qū)?,可以左右滑?dòng),然后就進(jìn)入應(yīng)用的主界面了,下面我們就實(shí)現(xiàn)這個(gè)功能2013-11-11

