欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android組件TabHost實現(xiàn)頁面中多個選項卡切換效果

 更新時間:2016年05月25日 15:20:34   投稿:lijiao  
這篇文章主要為大家詳細介紹了Android組件TabHost實現(xiàn)頁面中多個選項卡切換效果的相關資料,感興趣的小伙伴們可以參考一下

TabHost組件可以在界面中存放多個選項卡, 很多軟件都使用了改組件進行設計。
一、基礎知識
TabWidget : 該組件就是TabHost標簽頁中上部 或者 下部的按鈕, 可以點擊按鈕切換選項卡;
TabSpec : 代表了選項卡界面, 添加一個TabSpec即可添加到TabHost中;
-- 創(chuàng)建選項卡 : newTabSpec(String tag), 創(chuàng)建一個選項卡;
-- 添加選項卡 : addTab(tabSpec);

二、實例講解
TabHost的基本使用,主要是layout的聲明要使用特定的id號,然后activity繼承TabActivity即可。

main.xml:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@android:id/tabhost"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".Main" >

  <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="wrap_content" >

      <LinearLayout
        android:id="@+id/tab1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:text="aa" />
      </LinearLayout>

      <LinearLayout
        android:id="@+id/tab2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:text="bb" />
      </LinearLayout>
    </FrameLayout>
  </LinearLayout>

</TabHost>

Main.java:

package com.app.main;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;

public class Main extends TabActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final TabHost tabHost = this.getTabHost();

    TabSpec tab1 = tabHost.newTabSpec("tab1").setIndicator("tab1")
        .setContent(R.id.tab1);

    tabHost.addTab(tab1);

    TabSpec tab2 = tabHost.newTabSpec("tab2").setIndicator("tab2")
        .setContent(R.id.tab2);

    tabHost.addTab(tab2);


  }

}

實現(xiàn)效果:

其他:

當點擊tabwidget的時候,若想注冊事件監(jiān)聽器,可以使用:

1.調用

tabHost.setOnTabChangedListener(new TabChangeListener(){

  public void onTabChanged(String id)

    {
    }

});

這個傳入的id,就是tabwidget的indicator,這里是"tab1","tab2";

2.調用

tabWidget.getChildAt(0).setOnClickListener(new OnClickListener(){


});

以上就是本文的全部內容,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • Android 未讀消息的紅點顯示

    Android 未讀消息的紅點顯示

    本篇文章主要介紹了"Android基礎—未讀消息的紅點顯示", 在很多APP里面,經(jīng)常會看到未讀消息的小紅點,如下圖:這個功能用到的是一個控件,叫做BadgeView。 BadgeView的用法很簡單,直接把jar文件導入
    2017-04-04
  • Android仿QQ消息提示點拖拽功能

    Android仿QQ消息提示點拖拽功能

    這篇文章主要為大家詳細介紹了Android仿QQ消息提示點拖拽功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Android實現(xiàn)Activity水平和垂直滾動條的方法

    Android實現(xiàn)Activity水平和垂直滾動條的方法

    這篇文章主要介紹了Android實現(xiàn)Activity水平和垂直滾動條的方法,涉及Activity的ScrollView設置相關技巧,需要的朋友可以參考下
    2016-07-07
  • Android搜索框(SearchView)的功能和用法詳解

    Android搜索框(SearchView)的功能和用法詳解

    這篇文章主要為大家詳細介紹了Android搜索框SearchView的功能和用法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Android 獲取服務器與客戶端時差的實例代碼

    Android 獲取服務器與客戶端時差的實例代碼

    下面小編就為大家分享一篇Android 獲取服務器與客戶端時差的實例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • 利用Android中的TextView實現(xiàn)逐字顯示動畫

    利用Android中的TextView實現(xiàn)逐字顯示動畫

    在安卓程序啟動的時候,想逐字顯示一段話,每個字都有一個從透明到不透明的漸變動畫。那如何顯示這個效果,下面一起來看看。
    2016-08-08
  • 獲取Android系統(tǒng)唯一識別碼的方法

    獲取Android系統(tǒng)唯一識別碼的方法

    這篇文章主要介紹了獲取Android系統(tǒng)唯一識別碼的方法,涉及通過編程獲取Android系統(tǒng)硬件設備標識的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-10-10
  • Android View類與SurfaceView類詳解

    Android View類與SurfaceView類詳解

    本文主要介紹Android View類與SurfaceView類,這里提供了詳細的Android View類和SurfaceView類的使用方法,有興趣的小伙伴可以參考下
    2016-08-08
  • android自定義左側滑出菜單效果

    android自定義左側滑出菜單效果

    這篇文章主要為大家詳細介紹了android自定義左側滑出菜單效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android NotificationManager簡單使用詳解

    Android NotificationManager簡單使用詳解

    這篇文章主要為大家詳細介紹了Android NotificationManager的簡單使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11

最新評論