Android編程實(shí)現(xiàn)將tab選項(xiàng)卡放在屏幕底部的方法
本文實(shí)例講述了Android編程實(shí)現(xiàn)將tab選項(xiàng)卡放在屏幕底部的方法。分享給大家供大家參考,具體如下:
今天寫Tab的時(shí)候由于TAB的跳轉(zhuǎn)問題去查資料,倒反而發(fā)現(xiàn)更有趣的問題,就是如何將TAB放置在屏幕的底端。有點(diǎn)類似IPhone里的布局了,呵呵~(其實(shí)后來發(fā)現(xiàn)這個(gè)應(yīng)該不是用TAB做的,而是ButtonBar做出來的吧,或者是他重寫了TAB?總之不是簡單地將TAB放置底端了)。
要放置底端,那么Android自帶的例程是不可以做到的(例程參看development-ApiDemo)。先需要寫一個(gè)xml的layout文檔,命名為bottomtab.xml。
<?xml version="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:androidLinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/edit_item_tab_host"
android:layout_width="fill_parent"android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayoutandroid:idFrameLayoutandroid:id="@android:id/tabcontent"
android:layout_width="fill_parent"android:layout_height="wrap_content"
android:padding="5dp" android:layout_weight="1"/>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</LinearLayout>
然后以下就是完整的代碼了:
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TestTab extends ActivityGroup {
publicstatic TabHost tab_host;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bottomtab);
tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
tab_host.setup(this.getLocalActivityManager());
TabSpec ts1 = tab_host.newTabSpec("TAB_WEATHER");
ts1.setIndicator("Weather");
ts1.setContent(new Intent(this, Weather.class));
tab_host.addTab(ts1);
TabSpec ts2 = tab_host.newTabSpec("TAB_MAIL");
ts2.setIndicator("Mail");
ts2.setContent(new Intent(this, MailSend.class));
tab_host.addTab(ts2);
TabSpec ts3 = tab_host.newTabSpec("TAB_JUMP");
ts3.setIndicator("Jump");
ts3.setContent(new Intent(this, TabJump.class));
tab_host.addTab(ts3);
tab_host.setCurrentTab(0);
}
}
而關(guān)于頁面的跳轉(zhuǎn),就是:
TestTab.tabHost.setCurrentTab(0);
如此這般,就形成了下面的這個(gè)東西,其實(shí)還沒有放在上面好看。。。所以也證實(shí)了上面那個(gè)應(yīng)用不是簡單地放置TAB在底端了。有機(jī)會還是再看看ButtonBar了。
注意:Weather.class 等Activity要在 在AndroidMenifest.xml添加聲明
在 application tag之間加上如下代碼:
</activity> <activityandroid:nameactivityandroid:name=".Weather"> </activity> <activityandroid:nameactivityandroid:name=".MailSend"> </activity> <activityandroid:nameactivityandroid:name=".TabJump"> </activity>
PS:關(guān)于AndroidManifest.xml文件相關(guān)屬性功能可參考本站在線工具:
Android Manifest功能與權(quán)限描述大全:
http://tools.jb51.net/table/AndroidManifest
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- Android實(shí)現(xiàn)底部導(dǎo)航欄功能(選項(xiàng)卡)
- Android多個(gè)TAB選項(xiàng)卡切換效果
- Android仿微信底部實(shí)現(xiàn)Tab選項(xiàng)卡切換效果
- Android利用Fragment實(shí)現(xiàn)Tab選項(xiàng)卡效果
- Android實(shí)現(xiàn)類似網(wǎng)易新聞選項(xiàng)卡動態(tài)滑動效果
- Android編程實(shí)現(xiàn)自定義Tab選項(xiàng)卡功能示例
- Android開發(fā)之選項(xiàng)卡功能的實(shí)現(xiàn)方法示例
- Android實(shí)現(xiàn)知乎選項(xiàng)卡動態(tài)隱藏效果實(shí)例
相關(guān)文章
Android圖片異步加載框架Android-Universal-Image-Loader
這篇文章主要介紹了Android圖片異步加載框架Android-Universal-Image-Loader,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
Android系統(tǒng)狀態(tài)欄定制圖標(biāo)顯示邏輯控制
這篇文章主要為大家介紹了Android系統(tǒng)狀態(tài)欄定制圖標(biāo)顯示邏輯控制,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Android Studio新建工程默認(rèn)在build.gradle中加入maven阿里源的問題
這篇文章主要介紹了Android Studio新建工程默認(rèn)在build.gradle中加入maven阿里源的問題,本文通過實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Android 獲取應(yīng)用緩存大小與清除緩存的方法
今天小編就為大家分享一篇Android 獲取應(yīng)用緩存大小與清除緩存的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
Android開發(fā)之SeekBar基本使用及各種美觀樣式示例
這篇文章主要介紹了Android開發(fā)之SeekBar基本使用及各種美觀樣式,結(jié)合實(shí)例形式分析了Android SeekBar控件的功能及樣式改變相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
朋友圈實(shí)現(xiàn)圖片+文字轉(zhuǎn)發(fā)功能(必看篇)
下面小編就為大家?guī)硪黄笥讶?shí)現(xiàn)圖片+文字轉(zhuǎn)發(fā)功能(必看篇)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03
Android自定義View實(shí)現(xiàn)內(nèi)存清理加速球效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)內(nèi)存清理加速球的效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02

