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

Android Tabhost使用方法詳解

 更新時(shí)間:2016年06月01日 16:43:50   作者:楊先生  
這篇文章主要為大家詳細(xì)介紹了Android Tabhost使用方法,如何利用TabHost 實(shí)現(xiàn)tab視圖,感興趣的小伙伴們可以參考一下

Android 實(shí)現(xiàn)tab視圖有2種方法,一種是在布局頁面中定義<tabhost>標(biāo)簽,另一種就是繼承tabactivity.但是我比較喜歡第二種方式,應(yīng)為如果頁面比較復(fù)雜的話你的XML文件會(huì)寫得比較龐大,用第二種方式XML頁面相對(duì)要簡(jiǎn)潔得多。

下面是我的XML源碼:

<FrameLayout 
 xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 > 
 <ListView 
   android:id="@+id/journals_list_one" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:cacheColorHint="#FFFFFFFF" 
   android:scrollbars="vertical" 
   android:paddingTop="5dip" 
   android:paddingBottom="5dip" 
   android:paddingRight="5dip" 
   android:background="#FFFFFFFF" 
   android:listSelector="@drawable/list_item_selecter" 
   /> 
 <ListView 
   android:id="@+id/journals_list_two" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:cacheColorHint="#FFFFFFFF" 
   android:scrollbars="vertical" 
   android:paddingTop="5dip" 
   android:paddingBottom="5dip" 
   android:paddingRight="5dip" 
   android:background="#FFFFFFFF" 
   /> 
 <ListView 
   android:id="@+id/journals_list_three" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:cacheColorHint="#FFFFFFFF" 
   android:scrollbars="vertical" 
   android:paddingTop="5dip" 
   android:paddingBottom="5dip" 
   android:paddingRight="5dip" 
   android:background="#FFFFFFFF" 
   /> 
 <ListView 
   android:id="@+id/journals_list_end" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:cacheColorHint="#FFFFFFFF" 
   android:scrollbars="vertical" 
   android:paddingTop="5dip" 
   android:paddingBottom="5dip" 
   android:paddingRight="5dip" 
   android:background="#FFFFFFFF" 
   /> 
</FrameLayout> 

這是JAVA源碼:

private TabHost tabHost; 
private ListView listView; 
private MyListAdapter adapter; 
private View footerView; 
private List<Map<String, String>> data = new ArrayList<Map<String, String>>(); 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 tabHost = this.getTabHost(); 
 
 LayoutInflater.from(this).inflate(R.layout.main, 
   tabHost.getTabContentView(), true); 
 
 tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("", 
   getResources().getDrawable(R.drawable.home)).setContent( 
   R.id.journals_list_one)); 
 tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("", 
   getResources().getDrawable(R.drawable.activity)).setContent( 
   R.id.journals_list_two)); 
 tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("", 
   getResources().getDrawable(R.drawable.community)).setContent( 
   R.id.journals_list_three)); 
 tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("", 
   getResources().getDrawable(R.drawable.shop)).setContent( 
   R.id.journals_list_end)); 
 
 tabHost.setCurrentTab(0); 
 setContentView(tabHost); 
 tabHost.setOnTabChangedListener(tabChangeListener); 
 
 showContent(); 
 
} 

 讓自己的類繼承TabActivity,然后通過調(diào)用getTabHost()方法得到tabhost對(duì)象,然后把自己寫好的數(shù)據(jù)展示的布局文件加載到tabhost中,就可以實(shí)現(xiàn)了。最后是通過調(diào)用addTab()方法添加標(biāo)簽的相關(guān)屬性(如:標(biāo)簽名稱,標(biāo)簽圖片,標(biāo)簽內(nèi)容布局)。

而如果通過XML文件配置tabHost則需要注意的是,framelayout,tabwidge標(biāo)簽的id都必須引用系統(tǒng)的id(@android:id/tabcontent,@android:id/tabs),不然會(huì)報(bào)異常.在程序用使用findViewById()加載tabhost,然后調(diào)用tabhost.setup()方法初始化tabhost,后面的步驟則和上面一種一樣,就不在說明。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

泰来县| 象山县| 太仓市| 吐鲁番市| 葫芦岛市| 洪江市| 鲜城| 剑河县| 蒙阴县| 丹江口市| 万年县| 孟州市| 江都市| 内黄县| 泾阳县| 阿克苏市| 普兰县| 金寨县| 磐石市| 双江| 巴林右旗| 太原市| 湟源县| 宜兰市| 胶州市| 阜南县| 林周县| 武威市| 霸州市| 邵武市| 和静县| 康平县| 梁平县| 抚顺县| 天峻县| 大方县| 北宁市| 丹江口市| 古田县| 梁河县| 增城市|