最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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.調(diào)用

tabHost.setOnTabChangedListener(new TabChangeListener(){

  public void onTabChanged(String id)

    {
    }

});

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

2.調(diào)用

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


});

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

相關文章

最新評論

黔江区| 乌鲁木齐县| 宁波市| 进贤县| 慈利县| 彝良县| 普安县| 明星| 大新县| 晋州市| 云林县| 牡丹江市| 韩城市| 北碚区| 绵阳市| 密山市| 曲沃县| 临潭县| 繁峙县| 鄂托克旗| 克东县| 富阳市| 治多县| 高陵县| 奇台县| 麻阳| 长沙市| 洪洞县| 吉安县| 浪卡子县| 深水埗区| 兴安盟| 广州市| 乌兰县| 忻州市| 陆良县| 寿阳县| 江油市| 伽师县| 高安市| 广元市|