国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android編程實現將tab選項卡放在屏幕底部的方法

2019-10-23 19:44:11
字體:
來源:轉載
供稿:網友

本文實例講述了Android編程實現將tab選項卡放在屏幕底部的方法。分享給大家供大家參考,具體如下:

今天寫Tab的時候由于TAB的跳轉問題去查資料,倒反而發現更有趣的問題,就是如何將TAB放置在屏幕的底端。有點類似IPhone里的布局了,呵呵~(其實后來發現這個應該不是用TAB做的,而是ButtonBar做出來的吧,或者是他重寫了TAB?總之不是簡單地將TAB放置底端了)。

要放置底端,那么Android自帶的例程是不可以做到的(例程參看development-ApiDemo)。先需要寫一個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);  }}

而關于頁面的跳轉,就是:

TestTab.tabHost.setCurrentTab(0);

如此這般,就形成了下面的這個東西,其實還沒有放在上面好看。。。所以也證實了上面那個應用不是簡單地放置TAB在底端了。有機會還是再看看ButtonBar了。

注意:Weather.class 等Activity要在 在AndroidMenifest.xml添加聲明

在 application tag之間加上如下代碼:

</activity>   <activityandroid:nameactivityandroid:name=".Weather"></activity>   <activityandroid:nameactivityandroid:name=".MailSend"></activity>   <activityandroid:nameactivityandroid:name=".TabJump"></activity>

希望本文所述對大家Android程序設計有所幫助。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 娄底市| 阿尔山市| 乌拉特中旗| 莱西市| 子长县| 隆化县| 伊宁市| 涟源市| 右玉县| 柘城县| 昌宁县| 达拉特旗| 黄梅县| 丹寨县| 西乌珠穆沁旗| 大庆市| 靖江市| 丹东市| 开封市| 永年县| 汨罗市| 白城市| 营山县| 汾西县| 周口市| 沁阳市| 八宿县| 普安县| 河池市| 茂名市| 阳新县| 普兰店市| 吉木萨尔县| 平阴县| 常熟市| 富锦市| 内江市| 神农架林区| 侯马市| 富蕴县| 广汉市|