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

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

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

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

二、實(shí)例講解
TabHost的基本使用,主要是layout的聲明要使用特定的id號(hào),然后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);


  }

}

實(shí)現(xiàn)效果:

其他:

當(dāng)點(diǎn)擊tabwidget的時(shí)候,若想注冊(cè)事件監(jiān)聽器,可以使用:

1.調(diào)用

tabHost.setOnTabChangedListener(new TabChangeListener(){

  public void onTabChanged(String id)

    {
    }

});

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

2.調(diào)用

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


});

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

相關(guān)文章

  • Android 未讀消息的紅點(diǎn)顯示

    Android 未讀消息的紅點(diǎn)顯示

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

    Android仿QQ消息提示點(diǎn)拖拽功能

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

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

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

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

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

    Android 獲取服務(wù)器與客戶端時(shí)差的實(shí)例代碼

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

    利用Android中的TextView實(shí)現(xiàn)逐字顯示動(dòng)畫

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

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

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

    Android View類與SurfaceView類詳解

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

    android自定義左側(cè)滑出菜單效果

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

    Android NotificationManager簡單使用詳解

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

最新評(píng)論