Fragment + TabHost + RadioGroup(一)

2015-01-27 06:10:49 · 作者: · 浏览: 21
1. 使用FragMent是因为 4.0.3之后 ,摒弃了TabActivity这种用法,

Demo 效果图:

height=323

?

先上布局XML R.layout.activity_main

?

[html]??
  1. xmlns:android=http://schemas.android.com/apk/res/android
  2. android:id=@android:id/tabhost
  3. android:layout_width=fill_parent
  4. android:layout_height=fill_parent>
  5. android:orientation=vertical
  6. android:layout_width=fill_parent
  7. android:layout_height=fill_parent>
  8. ?
  9. android:id=@android:id/tabs
  10. android:layout_width=fill_parent
  11. android:layout_height=wrap_content
  12. android:layout_weight=0.0
  13. android:visibility=gone/>
  14. ?
  15. layout=@layout/my_header
  16. android:layout_height=wrap_content
  17. android:layout_width=fill_parent/>
  18. ?
  19. android:id=@android:id/tabcontent
  20. android:layout_width=fill_parent
  21. android:layout_height=0.0dip
  22. android:layout_weight=1.0>
  23. ?
  24. android:name=com.example.coolsmile.fragment.HomeFragment
  25. android:id=@+id/HomeFragment
  26. android:layout_width=match_parent
  27. android:layout_height=match_parent
  28. />
  29. android:name=com.example.coolsmile.fragment.fragment_tab2
  30. android:id=@+id/fragment_tab2
  31. android:layout_width=match_parent
  32. android:layout_height=match_parent
  33. />
  34. android:id=@+id/fragment_tab3
  35. android:name=com.example.coolsmile.fragment.fragment_tab3
  36. android:layout_width=match_parent
  37. android:layout_height=match_parent
  38. />
  39. android:id=@+id/fragment_tab4
  40. android:name=com.example.coolsmile.fragment.fragment_tab4
  41. android:layout_width=match_parent
  42. android:layout_height=match_parent
  43. />
  44. android:id=@+id/fragment_tab5
  45. android:name=com.example.coolsmile.fragment.fragment_tab5
  46. android:layout_width=match_parent
  47. android:layout_height=match_parent
  48. />
  49. ?
  50. ?
  51. android:id=@+id/main_tab
  52. android:background=@drawable/bottom1
  53. android:orientation=horizontal
  54. android:layout_width=fill_parent
  55. android:layout_height=wrap_content
  56. android:gravity=center_vertical
  57. android:layout_gravity=bottom>
  58. ?
  59. android:id=@+id/main_tab_home
  60. style=@style/MMTabButton
  61. android:layout_weight=1.0
  62. android:drawableTop=@drawable/menu_icon_0_normal
  63. android:text=@string/main_home/>
  64. android:id=@+id/main_tab_info
  65. style=@style/MMTabButton
  66. android:layout_weight=1.0
  67. android:drawableTop=@drawable/menu_icon_1_normal
  68. android:text=@string/main_my_info />
  69. android:id=@+id/main_tab_news
  70. style=@style/MMTabButton
  71. android:layout_weight=1.0
  72. android:drawableTop=@drawable/menu_icon_2_normal
  73. android:text=@string/main_news />
  74. android:id=@+id/main_tab_search
  75. style=@style/MMTabButton
  76. android:layout_weight=1.0
  77. android:drawableTop=@drawable/menu_icon_3_normal
  78. android:text=@string/main_search/>
  79. android:id=@+id/main_tab_settings
  80. style=@style/MMTabButton
  81. android:layout_weight=1.0
  82. android:drawableTop=@drawable/menu_icon_3_normal
  83. android:focusable=false
  84. android:text=@string/main_settings />
  85. ?
  86. ?
  87. ?
  88. ?
  89. android:id=@+id/main_tab_new_message
  90. android:layout_width=wrap_content
  91. android:layout_height=wrap_content
  92. android:layout_gravity=center_horizontal|top
  93. android:layout_marginLeft=15dip
  94. android:layout_marginTop=-46dip
  95. android:background=@drawable/tips
  96. android:gravity=center
  97. android:textColor=#ffffff
  98. android:textSize=10sp
  99. android:visibil