Android底部菜单的封装及重用..docx

  1. 1、本文档共10页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Android底部菜单的封装及重用.

Android底部菜单的封装及重用引言 在Android的应用中,经常会见到底部菜单,例如微信的底部菜单如下所示:? 而在企业级的Android应用中,也存在同样的需求,但与微信这些大众软件的区别在于企业级的Android应用由于UI页面很多,每个页面都需要有底部菜单,而且每个页面的底部菜单按钮还可能完全不一样,所以,为了使每个页面保持一致性并为UI页面制作时提供便利,针对底部菜单进行专门的设计封装,就显得特别重要。?设计选型 在设计底部菜单时,有下面两种思路: 一、单独定制底部菜单块,并将菜单块代码引入到每一个需要使用到底部菜单的layout.xml文件中,然后再在代码中定义需要使用的按钮。?此方法符合正常思维逻辑,缺点在于每个页面都要重复去引入,其实这个是可以省掉的。? 二、Android中,可以将某块自定义的UI从layout.xml中实例化出来使用,使用的是LayoutInflater,基于该技术,我们可以换一种思路来解决这个问题:写页面layout文件的时候不用关心底部菜单。然后在展示的代码中,定义一个大的视图页面将页面的layout文件以及底部菜单的layout包含进来,过程如下图所示:详细设计 1.设计大的视图页面layout:bottom_menu_layout.xml,该页面用来包含以后自定义的业务页面,以及底部菜单。?xml version=1.0encoding=utf-8?LinearLayout xmlns:android=/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical LinearLayout android:orientation=horizontalandroid:layout_width=fill_parent android:gravity=bottom android:layout_height=wrap_content android:id=@+id/bottom_menu_button_group_id /LinearLayout /LinearLayout 2.设计底部菜单按钮layout:bottom_menu_button_frame.xml,该页面用来定义每一个按钮的样式,一般需要包含一个位于上方的图片以及一个位于下方的按钮文字。?xml version=1.0encoding=utf-8?LinearLayout xmlns:android=/apk/res/android android:orientation=vertical android:layout_width=64px android:layout_height=wrap_content android:id=@+id/bottom_menu_template_button_id android:background=@drawable/tab_one_normal ImageView android:id=@+id/bottom_menu_template_img_id android:paddingTop=5pxandroid:layout_gravity=center android:layout_width=wrap_content android:layout_height=wrap_content android:src=@drawable/image / TextView android:layout_width=wrap_contentandroid:id=@+id/bottom_menu_template_text_id android:layout_height=wrap_content android:layout_gravity=center android:gravity=center android:textSize=11spandroid:paddingBottom=5px //LinearLayout 3.自定义封装按钮的JAVA类:BottomButton,封装底部菜单按钮的基本信息:图片、文字、按钮事件、是否当前被选中的按钮等。public class BottomButton{ // 按钮菜单文字 private String text; // 按钮菜单图片 private int backgroundResource; // 点击事件。 private View.OnClickListener clickListener; // 是否当前已经选中的按钮,如果是则高亮,并且忽略点击事件。 pr

文档评论(0)

dashewan + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档