最新国产好看的视频,伊人天堂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頁面相對要簡潔得多。

下面是我的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對象,然后把自己寫好的數(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,后面的步驟則和上面一種一樣,就不在說明。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實(shí)現(xiàn)消水果游戲代碼分享

    Android實(shí)現(xiàn)消水果游戲代碼分享

    本文給大家分享實(shí)現(xiàn)開心消水果游戲的核心代碼,代碼簡單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友一起看看吧
    2016-11-11
  • android使用SoundPool播放音效的方法

    android使用SoundPool播放音效的方法

    本篇文章主要介紹了android使用SoundPool播放音效的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • android實(shí)現(xiàn)視頻的加密和解密(使用AES)

    android實(shí)現(xiàn)視頻的加密和解密(使用AES)

    本篇文章主要介紹了android實(shí)現(xiàn)視頻的加密和解密(使用AES),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • Android實(shí)現(xiàn)仿微軟系統(tǒng)加載動(dòng)畫效果

    Android實(shí)現(xiàn)仿微軟系統(tǒng)加載動(dòng)畫效果

    這篇文章主要介紹了Android實(shí)現(xiàn)仿微軟系統(tǒng)加載動(dòng)畫效果的方法,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-04-04
  • Android中自定義ContentProvider實(shí)例

    Android中自定義ContentProvider實(shí)例

    應(yīng)用A(TestBaidu)調(diào)用另外一個(gè)應(yīng)用(TestContentProvider)中的自定義ContentProvider,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈
    2013-06-06
  • Android 中ScrollView與ListView沖突問題的解決辦法

    Android 中ScrollView與ListView沖突問題的解決辦法

    這篇文章主要介紹了Android 中ScrollView與ListView沖突問題的解決辦法的相關(guān)資料,希望通過本文能幫助到大家,讓大家掌握解決問題的辦法,需要的朋友可以參考下
    2017-10-10
  • Android 文件數(shù)據(jù)存儲(chǔ)實(shí)例詳解

    Android 文件數(shù)據(jù)存儲(chǔ)實(shí)例詳解

    這篇文章主要介紹了Android 文件數(shù)據(jù)存儲(chǔ)實(shí)例詳解的相關(guān)資料,這里附有實(shí)例代碼,幫助大家學(xué)習(xí)理解,需要的朋友可以參考下
    2016-12-12
  • Android開發(fā)入門之對話框簡單用法

    Android開發(fā)入門之對話框簡單用法

    這篇文章主要介紹了Android對話框簡單用法,涉及Android對話框的功能、定義、創(chuàng)建及使用等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-07-07
  • android中把文件保存到sdcard代碼實(shí)例

    android中把文件保存到sdcard代碼實(shí)例

    這篇文章主要介紹了android中把文件保存到sdcard代碼實(shí)例,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-05-05
  • Android 網(wǎng)絡(luò)請求框架解析之okhttp與okio

    Android 網(wǎng)絡(luò)請求框架解析之okhttp與okio

    HTTP是現(xiàn)代應(yīng)用常用的一種交換數(shù)據(jù)和媒體的網(wǎng)絡(luò)方式,高效地使用HTTP能讓資源加載更快,節(jié)省帶寬,OkHttp是一個(gè)高效的HTTP客戶端,下面這篇文章主要給大家介紹了關(guān)于OkHttp如何用于安卓網(wǎng)絡(luò)請求,需要的朋友可以參考下
    2021-10-10

最新評論

定州市| 越西县| 德惠市| 甘洛县| 奉节县| 花莲县| 湖南省| 余姚市| 禹州市| 依安县| 磐安县| 朔州市| 靖安县| 苍溪县| 贵德县| 清丰县| 霍山县| 舟山市| 米林县| 云林县| 新邵县| 乌兰浩特市| 米脂县| 盘山县| 丘北县| 普陀区| 南和县| 镇巴县| 平山县| 滨州市| 丰顺县| 莫力| 嵊州市| 岳池县| 和顺县| 阿拉善左旗| 泸水县| 巴马| 西盟| 峡江县| 石嘴山市|