Android簡單實現(xiàn)屏幕下方Tab菜單的方法
本文實例講述了Android簡單實現(xiàn)屏幕下方Tab菜單的方法。分享給大家供大家參考,具體如下:
看到很多熱門的Android程序(如:新浪微博、騰訊微博、京東商城、淘寶、當(dāng)當(dāng)?shù)鹊龋┦褂眠x項卡風(fēng)格作為程序界面的主框架結(jié)構(gòu),而Android的選項卡控件默認(rèn)是按鈕在上方的。我在網(wǎng)上看到有多種實現(xiàn)方法,這里提供一種個人覺得比較簡單的。由于我對Android開發(fā)所知甚少,方法的優(yōu)劣目前不好評價,歡迎各位提供更好的思路。
主要原理:設(shè)置 TabWidget 控件的 android:layout_alignParentBottom="true" 實現(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)容感興趣的讀者可查看本站專題:《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android 中TabLayout自定義選擇背景滑塊的實例代碼
- Android中TabLayout結(jié)合ViewPager實現(xiàn)頁面切換效果
- Android實現(xiàn)為Tab添加Menu的方法
- Android實現(xiàn)App中導(dǎo)航Tab欄懸浮的功能
- Android TabLayout實現(xiàn)京東詳情效果
- Android實現(xiàn)仿微信tab高亮icon粘著手的滑動效果
- android TabLayout使用方法詳解
- android中實現(xiàn)背景圖片顏色漸變方法
- 關(guān)注Ionic底部導(dǎo)航按鈕tabs在android情況下浮在上面的處理
- Android 微信6.1 tab欄圖標(biāo)和字體顏色漸變的實現(xiàn)
相關(guān)文章
Android中TextView實現(xiàn)部分文字可點擊跳轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Android中TextView實現(xiàn)部分文字可點擊跳轉(zhuǎn)的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10
Android開發(fā)之圖片旋轉(zhuǎn)功能實現(xiàn)方法【基于Matrix】
這篇文章主要介紹了Android開發(fā)之圖片旋轉(zhuǎn)功能實現(xiàn)方法,結(jié)合實例形式分析了Android基于matrix矩陣操作圖形變換的相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2017-09-09
解決Android加殼過程中mprotect調(diào)用失敗的原因分析
本文探討的主要內(nèi)容是mprotect調(diào)用失敗的根本原因,以及在加殼實現(xiàn)中的解決方案,通過本文的闡述,一方面能夠幫助遇到同類問題的小伙伴解決心中的疑惑,另一方面能夠給大家提供可落地的實現(xiàn)方案,需要的朋友可以參考下2022-01-01
項目發(fā)布Debug和Release版的區(qū)別詳解
這篇文章主要為大家詳細(xì)介紹了項目發(fā)布Debug和Release版的區(qū)別,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-10-10
Android之利用EventBus發(fā)送消息傳遞示例
本篇文章主要介紹了Android之利用EventBus進(jìn)行消息傳遞示例。EventBus是一款針對Android優(yōu)化的發(fā)布/訂閱事件總線,非常具有實用價值,需要的朋友可以參考下。2017-02-02
Android 6.0上sdcard和U盤路徑獲取和區(qū)分方法
今天小編就為大家分享一篇Android 6.0上sdcard和U盤路徑獲取和區(qū)分方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
RecycleView實現(xiàn)item側(cè)滑刪除與拖拽
這篇文章主要為大家詳細(xì)介紹了RecycleView實現(xiàn)item側(cè)滑刪除與拖拽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-11-11
Android基于注解的6.0權(quán)限動態(tài)請求框架詳解
這篇文章主要介紹了Android基于注解的6.0權(quán)限動態(tài)請求框架詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04

