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)文章
Android中實(shí)現(xiàn)多線程操作的幾種方式
多線程一直是一個(gè)老大難的問(wèn)題,首先因?yàn)樗y以理解,其次在實(shí)際工作中我們需要面對(duì)的關(guān)于線程安全問(wèn)題也并不常見(jiàn),今天就來(lái)總結(jié)一下實(shí)現(xiàn)多線程的幾種方式,感興趣的可以了解一下2021-06-06Android實(shí)現(xiàn)傾斜角標(biāo)樣式
最新小編接到這樣一個(gè)項(xiàng)目,需要在一個(gè)距形卡片上做一個(gè)傾斜的Tag,類似支付寶上的一個(gè)功能,接著小編給大家?guī)?lái)了實(shí)現(xiàn)思路,對(duì)android 傾斜角標(biāo)的實(shí)現(xiàn)方法感興趣的朋友跟隨小編一起看看吧2019-10-10flutter升級(jí)3.7.3報(bào)錯(cuò)Unable?to?find?bundled?Java?version解決
這篇文章主要介紹了flutter升級(jí)3.7.3報(bào)錯(cuò)Unable?to?find?bundled?Java?version解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加2023-02-02Android 自定義SeekBar動(dòng)態(tài)改變硬件音量大小實(shí)現(xiàn)和音量鍵的同步(推薦)
這篇文章主要介紹了 Android 自定義SeekBar動(dòng)態(tài)改變硬件音量大小實(shí)現(xiàn)和音量鍵的同步效果,整段代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01android TextView 設(shè)置和取消刪除線的兩種方法
這篇文章主要介紹了android TextView 設(shè)置和取消刪除線的兩種方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03android圖像繪制(六)獲取本地圖片或拍照?qǐng)D片等圖片資源
從SD卡中獲取圖片資源,或者拍一張新的圖片,然后再進(jìn)行處理(直接處理返回圖片/獲得圖片的地址再處理)接下來(lái)為您詳細(xì)介紹,感興趣的朋友可以了解下2013-01-01Android 使用volley過(guò)程中遇到的問(wèn)題解決辦法
這篇文章主要介紹了Android 使用volley過(guò)程中遇到的問(wèn)題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-06-06