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

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)文章

最新評(píng)論

黎川县| 开阳县| 邵武市| 阳原县| 北流市| 武邑县| 嘉禾县| 彝良县| 中方县| 辉县市| 罗山县| 济阳县| 西林县| 太康县| 万山特区| 桃江县| 玉林市| 双牌县| 绍兴县| 涞源县| 雅江县| 赤水市| 开封市| 庐江县| 汤原县| 西安市| 全州县| 龙江县| 沛县| 宾川县| 灵武市| 金门县| 嵊泗县| 蛟河市| 固安县| 江永县| 阿克苏市| 扬中市| 德令哈市| 临桂县| 工布江达县|