Android小巫新闻客户端底部菜单切换实现.docx
- 文档编号:9443866
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:27
- 大小:172.68KB
Android小巫新闻客户端底部菜单切换实现.docx
《Android小巫新闻客户端底部菜单切换实现.docx》由会员分享,可在线阅读,更多相关《Android小巫新闻客户端底部菜单切换实现.docx(27页珍藏版)》请在冰豆网上搜索。
Android小巫新闻客户端底部菜单切换实现
Android-小巫新闻客户端底部菜单切换实现
2012年12月7日星期五
真快啊,12月了,到了一年的最后一个月,意味着学期也快要结束了。
小巫还在认真得学习着Android,尽管学习得不怎么样,但还是懂了些东西。
因为之前一直想不明白XX新闻客户端之前版本的底部菜单是如何实现的,后来网上查了一下,原来是如此简单。
所以照猫画虎也实现了自己想要的效果。
其实实现起来还蛮简单的,只是小巫想了很久没想出来而已。
这里有几个关键点:
1.用TabHost布局,需要声明id为android:
id="@android:
id/tabhost"
2.MainActivity需要继承TabActivity
3.实现OnCheckedChangeListener
4.通过getHost方法获取Tabhost
5.通过addTab方法添加选项卡
6.设置Activity跳转需要为每个选项卡setContent
7.在onCheckedChanged监听每一个选项卡
8.选项卡通过调用setCurrentTabByTag方法实现显示Activity
项目实例:
小巫新闻客户端的底部菜单实现
项目运行效果图:
创建项目:
ButtonMenuTest
首先来看看界面布局:
maintabs.xml
1.
xmlversion="1.0"encoding="UTF-8"?
>
2. android=" 3.android: id="@android: id/tabhost" 4.android: layout_width="match_parent" 5.android: layout_height="match_parent" 6.android: background="@drawable/main_background"> 7. 8. 9.android: layout_width="match_parent" 10.android: layout_height="match_parent" 11.android: orientation="vertical"> 12. 13. 14.android: id="@android: id/tabcontent" 15.android: layout_width="match_parent" 16.android: layout_height="0.0dip" 17.android: layout_weight="1.0"/> 18. 19. 20.android: id="@android: id/tabs" 21.android: layout_width="match_parent" 22.android: layout_height="wrap_content" 23.android: layout_weight="0.0" 24.android: visibility="gone"/> 25. 26. 27.android: id="@+id/main_radio" 28.android: layout_width="match_parent" 29.android: layout_height="wrap_content" 30.android: layout_gravity="bottom" 31.android: background="@drawable/image_tabbar_background" 32.android: gravity="center_vertical" 33.android: orientation="horizontal"> 34. 35. 36.android: id="@+id/home_button" 37.style="@style/main_tab_bottom" 38.android: layout_marginTop="8.0dip" 39.android: background="@drawable/image_tabbar_button_news_home_selector" 40.android: tag="home_button"/> 41. 42. 43.android: id="@+id/subscribe_button" 44.style="@style/main_tab_bottom" 45.android: layout_marginTop="8.0dip" 46.android: background="@drawable/image_tabbar_button_subscription_selector" 47.android: tag="subscribe_button"/> 48. 49. 50.android: id="@+id/hotnews_button" 51.style="@style/main_tab_bottom" 52.android: layout_marginTop="8.0dip" 53.android: background="@drawable/image_tabbar_button_hot_news_selector" 54.android: tag="hotnews_button"/> 55. 56. 57.android: id="@+id/financial_button" 58.style="@style/main_tab_bottom" 59.android: layout_marginTop="8.0dip" 60.android: background="@drawable/image_tabbar_button_financial_index_selector" 61.android: tag="financial_button"/> 62. 63. 64.android: id="@+id/search_button" 65.style="@style/main_tab_bottom" 66.android: layout_marginTop="8.0dip" 67.android: background="@drawable/image_tabbar_button_search_news_selector" 68.android: tag="search_button"/> 69. 70. 71. 72. style代码: styles.xml 1. xmlversion="1.0"encoding="utf-8"? > 2. android=" 3. Theme.Light"/> 4. 5. 6. textSize">@dimen/bottom_tab_font_size 7. textColor">#ff0000 8. ellipsize">marquee 9. gravity">center_horizontal 10. paddingTop">@dimen/bottom_tab_padding_up 11. layout_width">match_parent 12. layout_height">wrap_content 13. button">@null 14. singleLine">true 15. drawablePadding">@dimen/bottom_tab_padding_drawable 16. layout_weight">1.0 17. 18. news_home_layout.xml 1. android=" 2.xmlns: tools=" 3.android: id="@+id/main_layout" 4.android: layout_width="match_parent" 5.android: layout_height="wrap_content" 6.android: background="@drawable/main_background" 7.android: orientation="vertical"> 8. 9. 10.android: id="@id/titlebar_layout" 11.android: layout_width="match_parent" 12.android: layout_height="wrap_content" 13.android: background="@drawable/image_titlebar_background"> 14. 15. 16.android: layout_width="wrap_content" 17.android: layout_height="wrap_content" 18.android: layout_marginLeft="10.0dip" 19.android: layout_marginTop="9.0dip" 20.android: text="@string/app_name" 21.android: textColor="@color/white" 22.android: textSize="23.0sp"/> 23. 24. 44. 45. 46.android: id="@id/categorybar_layout" 47.android: layout_width="match_parent" 48.android: layout_height="wrap_content" 49.android: layout_marginTop="-16dip" 50.android: background="@drawable/image_categorybar_background"> 51. 52. 62. financial_index_layout.xml 1. android=" 2.xmlns: tools=" 3.android: id="@+id/financial_index_layout" 4.android: layout_width="match_parent" 5.android: layout_height="wrap_content" 6.android: background="@drawable/main_background" 7.android: orientation="vertical"> 8. 9. 10.android: id="@+id/titlebar_layout" 11.android: layout_width="match_parent" 12.android: layout_height="wrap_content" 13.android: background="@drawable/image_titlebar_background"> 14. 15. 16.android: layout_width="wrap_content" 17.android: layout_height="wrap_content" 18.android: layout_marginLeft="10.0dip" 19.android: layout_marginTop="9.0dip" 20.android: text="@string/financial_news" 21.android: textColor="@color/white" 22.android: textSize="23.0sp"/> 23. 24. 44. 45. 46.android: id="@+id/categorybar_layout" 47.android: layout_width="match_parent" 48.android: layout_height="wrap_content" 49.android: layout_marginTop="-16dip" 50.android: background="@drawable/image_categorybar_background"> 51. 52. 53. 54.android: id="@+id/categorybar_scrollView" 55.android: layout_width="match_parent" 56.android: layout_height="wrap_content" 57.android: layout_marginLeft="8dip" 58.android: layout_marginTop="3.0dip" 59.android: layout_toLeftOf="@+id/category_arrow_right" 60.android: scrollbars="none"> 61. 62. 63.android: id="@+id/category_layout" 64.android: layout_width="match_parent" 65.android: layout_height="match_parent" 66.android: gravity="center_vertical"> 67. 68. 69. 70. 71.android: id="@+id/financial_index_table_title_layout" 72.android: layout_width="match_parent" 73.android: layout_height="wrap_content" 74.android: layout_marginTop="-10.0dip" 75.android: background="@drawable/image_financial_index_table_title_background" 76.> 77. 78.android: id="@+id/txt1" 79.android: layout_width="wrap_content" 80.android: layout_height="wrap_content" 81.android: text="指数" 82.android: textColor="#000000" 83.android: layout_marginLeft="5.0dip" 84.android: layout_marginTop="5.0dip" 85.android: layout_alignParentLeft="true" 86./> 87. 88.android: id="@+id/txt2" 89.android: layout_width="wrap_content" 90.android: layout_height="wrap_content" 91.android: layout_toLeftOf="@+id/txt3" 92.android: text="最新价" 93.android: textColor="#000000" 94.android: layout_marginRight="10.0dip" 95.android: layout_margin
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 新闻 客户端 底部 菜单 切换 实现