Android簡(jiǎn)單實(shí)現(xiàn)屏幕下方Tab菜單的方法
本文實(shí)例講述了Android簡(jiǎn)單實(shí)現(xiàn)屏幕下方Tab菜單的方法。分享給大家供大家參考,具體如下:
看到很多熱門(mén)的Android程序(如:新浪微博、騰訊微博、京東商城、淘寶、當(dāng)當(dāng)?shù)鹊龋┦褂眠x項(xiàng)卡風(fēng)格作為程序界面的主框架結(jié)構(gòu),而Android的選項(xiàng)卡控件默認(rèn)是按鈕在上方的。我在網(wǎng)上看到有多種實(shí)現(xiàn)方法,這里提供一種個(gè)人覺(jué)得比較簡(jiǎn)單的。由于我對(duì)Android開(kāi)發(fā)所知甚少,方法的優(yōu)劣目前不好評(píng)價(jià),歡迎各位提供更好的思路。
主要原理:設(shè)置 TabWidget 控件的 android:layout_alignParentBottom="true" 實(shí)現(xiàn)。
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@+id/tabhost" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="@+id/tab1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
androidrientation="vertical">
<TextView android:id="@+id/view1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/textView_1" />
</LinearLayout>
<LinearLayout android:id="@+id/tab2"
android:layout_width="fill_parent" android:layout_height="fill_parent"
androidrientation="vertical">
<TextView android:id="@+id/view2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/textView_2" />
</LinearLayout>
<LinearLayout android:id="@+id/tab3"
android:layout_width="fill_parent" android:layout_height="fill_parent"
androidrientation="vertical">
<TextView android:id="@+id/view3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/textView_3" />
</LinearLayout>
<LinearLayout android:id="@+id/tab4"
android:layout_width="fill_parent" android:layout_height="fill_parent"
androidrientation="vertical">
<TextView android:id="@+id/view4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/textView_4" />
</LinearLayout>
</FrameLayout>
</RelativeLayout>
</TabHost>
zhnews.java:
package net.zhnews.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class zhnews extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
setTitle("珠海新聞網(wǎng)Android客戶端");
TabHost tabs = (TabHost) findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec = tabs.newTabSpec("tab1");
spec.setContent(R.id.tab1);
spec.setIndicator("新聞");
tabs.addTab(spec);
spec = tabs.newTabSpec("tab2");
spec.setContent(R.id.tab2);
spec.setIndicator("搜聯(lián)社");
tabs.addTab(spec);
spec = tabs.newTabSpec("tab3");
spec.setContent(R.id.tab3);
spec.setIndicator("影像");
tabs.addTab(spec);
spec = tabs.newTabSpec("tab4");
spec.setContent(R.id.tab4);
spec.setIndicator("設(shè)置");
tabs.addTab(spec);
tabs.setCurrentTab(0);
}
}
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android操作SQLite數(shù)據(jù)庫(kù)技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開(kāi)發(fā)之SD卡操作方法匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android 中TabLayout自定義選擇背景滑塊的實(shí)例代碼
- Android中TabLayout結(jié)合ViewPager實(shí)現(xiàn)頁(yè)面切換效果
- Android實(shí)現(xiàn)為T(mén)ab添加Menu的方法
- Android實(shí)現(xiàn)App中導(dǎo)航Tab欄懸浮的功能
- Android TabLayout實(shí)現(xiàn)京東詳情效果
- Android實(shí)現(xiàn)仿微信tab高亮icon粘著手的滑動(dòng)效果
- android TabLayout使用方法詳解
- android中實(shí)現(xiàn)背景圖片顏色漸變方法
- 關(guān)注Ionic底部導(dǎo)航按鈕tabs在android情況下浮在上面的處理
- Android 微信6.1 tab欄圖標(biāo)和字體顏色漸變的實(shí)現(xiàn)
相關(guān)文章
Android實(shí)現(xiàn)左側(cè)滑動(dòng)菜單
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)左側(cè)滑動(dòng)菜單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
Android轉(zhuǎn)場(chǎng)動(dòng)畫(huà)深入分析探究
對(duì)于一個(gè)動(dòng)畫(huà)而言,它是由多個(gè)分鏡頭組成的,而轉(zhuǎn)場(chǎng)就是分鏡之間銜接方式。轉(zhuǎn)場(chǎng)的主要目的,就是為了讓鏡頭與鏡頭之間過(guò)渡的更加自然,讓動(dòng)畫(huà)更加連貫,例如兩個(gè)頁(yè)面切換之間的銜接動(dòng)畫(huà)2022-10-10
Kotlin實(shí)現(xiàn)多函數(shù)接口的簡(jiǎn)化調(diào)用
這篇文章主要為大家詳細(xì)介紹了Kotlin實(shí)現(xiàn)多函數(shù)接口的簡(jiǎn)化調(diào)用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
Android實(shí)現(xiàn)評(píng)論欄隨Recyclerview滑動(dòng)左右移動(dòng)
這篇文章主要介紹了Android實(shí)現(xiàn)評(píng)論欄隨Recyclerview滑動(dòng)左右移動(dòng)效果,仿約會(huì)吧應(yīng)用詳情頁(yè)實(shí)現(xiàn),感興趣的小伙伴們可以參考一下2016-05-05
Android 監(jiān)聽(tīng)手機(jī)GPS打開(kāi)狀態(tài)實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 監(jiān)聽(tīng)手機(jī)GPS打開(kāi)狀態(tài)實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android中使用ShareSDK集成分享功能的實(shí)例代碼
下面小編就為大家分享一篇Android中使用ShareSDK集成分享功能的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
Android利用Intent啟動(dòng)和關(guān)閉Activity
這篇文章主要為大家詳細(xì)介紹了Android利用Intent啟動(dòng)和關(guān)閉Activity的相關(guān)操作,感興趣的小伙伴們可以參考一下2016-06-06
Android 自定義SeekBar 實(shí)現(xiàn)分段顯示不同背景顏色的示例代碼
這篇文章主要介紹了Android 自定義SeekBar 實(shí)現(xiàn)分段顯示不同背景顏色,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06

