亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

android 自定義tabhost的tabs 用gridview實現

系統 2299 0

2011.09.14(3)——— android 自定義tabhost的tabs?
參考: http://www.cnblogs.com/over140/archive/2011/03/02/1968042.html ?
Java代碼?? 收藏代碼
  1. http: //www.iteye.com/topic/1116261 ??


我們直接用系統的tabhost時 如下圖?
android 自定義tabhost的tabs  用gridview實現 ?

可以看見 兩個tab中間有空隙 也許我們不需要這些空隙或者系統的樣式 但是沒有相關的xml屬性來修改 所以我們可以自定義tabs?
效果如下圖 可以看見 沒有了中間的空隙?

?

我們用單選按鈕來實現tabs?


1、看布局文件?

Java代碼?? 收藏代碼
  1. <?xml?version= "1.0" ?encoding= "utf-8" ?>??
  2. <TabHost?xmlns:android= "http://schemas.android.com/apk/res/android" ??
  3. ????android:id= "@android:id/tabhost" ??
  4. ????android:layout_width= "fill_parent" ??
  5. ????android:layout_height= "fill_parent" ??
  6. ????android:background?=? "#d7d7d7" >??
  7. ????<LinearLayout?android:orientation= "vertical" ??
  8. ????????android:layout_width= "fill_parent" ??
  9. ????????android:layout_height= "fill_parent" >??
  10. ????????<FrameLayout?android:id= "@android:id/tabcontent" ??
  11. ????????????android:layout_width= "fill_parent" ??
  12. ????????????android:layout_height= "wrap_content" ??
  13. ????????????android:layout_weight?=? "1" >???????????
  14. ????????</FrameLayout>??????
  15. ??????????
  16. ????????<TabWidget?android:id= "@android:id/tabs" ??
  17. ????????????android:layout_width= "fill_parent" ??
  18. ????????????android:layout_height= "wrap_content" ??
  19. ????????????android:visibility?=? "gone" />??
  20. ?????????<RadioGroup?android:gravity= "right" ???
  21. ????????????????????android:layout_gravity= "bottom" ???
  22. ????????????????????android:orientation= "horizontal" ???
  23. ????????????????????android:id= "@+id/main_radio" ???????????????????????
  24. ????????????????????android:layout_width= "fill_parent" ???
  25. ????????????????????android:layout_height= "wrap_content" >??
  26. ??????????????
  27. ????????????<RadioButton???
  28. ????????????????android:id= "@+id/radio_contact" ???
  29. ????????????????android:layout_marginTop= "2.0dip" ??
  30. ????????????????android:background?=? "@drawable/tabcontact" ??
  31. ????????????????android:layout_width= "wrap_content" ???
  32. ????????????????android:layout_height= "fill_parent" ??
  33. ????????????????android:button=? "@null" ????????
  34. ????????????????/>??
  35. ????????????<RadioButton?android:checked= "true" ?????????????????
  36. ????????????????android:id= "@+id/radio_session" ???
  37. ????????????????android:layout_marginTop= "2.0dip" ??
  38. ????????????????android:background?=? "@drawable/tabsession" ??
  39. ????????????????android:layout_width= "wrap_content" ???
  40. ????????????????android:layout_height= "fill_parent" ??
  41. ????????????????android:button=? "@null" />????
  42. ????????????<RadioButton???
  43. ????????????????android:id= "@+id/radio_setting" ???
  44. ????????????????android:layout_marginTop= "2.0dip" ??
  45. ????????????????android:background?=? "@drawable/tabsetting" ??
  46. ????????????????android:layout_width= "wrap_content" ???
  47. ????????????????android:layout_height= "fill_parent" ??
  48. ????????????????android:button=? "@null" ??
  49. ????????????????/>?????????????????????????????????
  50. ????????</RadioGroup>???????????
  51. ????</LinearLayout>?????????
  52. </TabHost>??


關鍵 在于 TabWidget里面?
Java代碼?? 收藏代碼
  1. android:visibility?=? "gone" ??


2、代碼?

主要是三個方法:?

初始化Tabhost?
Java代碼?? 收藏代碼
  1. private ? void ?initTabHost()?{??
  2. ????????mTabHost?=?getTabHost();??
  3. ????????mTabHost.addTab(mTabHost.newTabSpec( "tab?session" ).setIndicator(??
  4. ???????????????? "" ).setContent( new ?Intent( this ,SessionListActivity. class )));??
  5. ????????mTabHost.addTab(mTabHost.newTabSpec( "tab?contact" ).setIndicator(??
  6. ???????????????? "" ).setContent( new ?Intent( this ,ContactListActivity. class )));??
  7. ????????mTabHost.addTab(mTabHost.newTabSpec( "tab?setting" ).setIndicator(??
  8. ???????????????? "" ).setContent( new ?Intent( this ,UserSettingActivitiy. class )));??
  9. ??????????
  10. ????????mTabHost.setCurrentTabByTag(_contactListTag);??
  11. ????????mTabHost.setCurrentTabByTag(_settingTag);??
  12. ????????mTabHost.setCurrentTabByTag(_sessionListTag);??
  13. ??????????
  14. ????}??


初始化RadioButton?
Java代碼?? 收藏代碼
  1. private ? void ?initTabWidget()?{??
  2. ?????????((RadioButton)?findViewById(R.id.radio_session)).setOnCheckedChangeListener( this );??
  3. ?????????((RadioButton)?findViewById(R.id.radio_contact)).setOnCheckedChangeListener( this );??
  4. ?????????((RadioButton)?findViewById(R.id.radio_setting)).setOnCheckedChangeListener( this );??
  5. ????}??


設置切換事件
??
Java代碼?? 收藏代碼
  1. @Override ??
  2. ??? public ? void ?onCheckedChanged(CompoundButton?buttonView,? boolean ?isChecked)?{??
  3. ??????? if ?(isChecked)?{??
  4. ??????????? switch ?(buttonView.getId())?{??
  5. ??????????? case ?R.id.radio_contact:??
  6. ??????????????? this .mTabHost.setCurrentTabByTag(_contactListTag);??
  7. ??????????????? break ;??
  8. ??????????? case ?R.id.radio_session:??
  9. ??????????????? this .mTabHost.setCurrentTabByTag(_sessionListTag);??
  10. ??????????????? break ;??
  11. ??????????? case ?R.id.radio_setting:??
  12. ???????????? this .mTabHost.setCurrentTabByTag(_settingTag);??
  13. ??????????????? break ;??????????????
  14. ???????????}??
  15. ???????}??
  16. ???}??



1.  由于TabWidget被隱藏,所以相關的事件也會無效,這里取巧用RadioGroup與RadioButton的特性來處理切換,然后監聽事件調用setCurrentTabByTag來切換Activity。?
2.  注意即使TabWidget被隱藏,也要為其設置indicator,否則會保持。
?

android 自定義tabhost的tabs 用gridview實現


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美性精品hd在线观看 | 免费福利在线视频 | 国产欧美日韩综合一区二区三区 | 国产精品久久香蕉免费播放 | 热99re久久精品这里都是免费 | 国产精品福利视频一区二区三区 | 久久久久久久国产a∨ | 国产精品免费观在线 | 亚洲第一欧美 | 老年人一级特黄aa大片 | 免费一级毛片在线视频观看 | 91中文字幕视频 | 国产成人精品s8sp视频 | 一级特级欧美a毛片免费 | 99国产精品一区二区 | 97精品视频在线 | 天天拍夜夜添久久精品中文 | 亚洲精品一区二区不卡 | 国产精品线在线精品国语 | 久久久久久999 | 国产精品久久久久久久免费 | 伊人久久在线视频 | 欧美日韩在线观看视频 | 久久精品网 | 国产精品免费aⅴ片在线观看 | 亚洲成人在线播放视频 | 一级特级女人18毛片免费视频 | 亚洲成色综合一区二区三区四区 | 天天做爽夜夜做爽 | 亚洲国产欧美一区 | 日本中文字幕在线观看视频 | 91精品国产高清久久久久 | 老子午夜精品我不卡影院 | 四虎新地址 | 日本αv| 中文字幕久热精品视频免费 | 欧美三级成人理伦 | aaa黑人一级毛片 | 日本色色网 | 狠狠色伊人亚洲综合成人 | 香蕉伊人网 |