Hyena-菜单项View

  • 先看下需求,下图是设置-开发者选项 里面的截图,里面有四种布局,不难看出他们有共同点,比如Title的样式是一样的,都有分割线等等。
设置-开发者选项.png
  • 鬣狗快速开发库中有一个自定义控件-MenuItemView。可以很好的实现上面的需求。
MenuItemView效果图
  • 举个粒子
xmlns:item="http://schemas.android.com/apk/res-auto"

<com.knifestone.hyena.view.viewgroup.MenuItemView
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    item:iv_left_size="35dp"
    item:iv_left_src="@mipmap/ic_launcher"
    item:iv_right_src="@drawable/ic_chevron_right_black_24dp"
    item:tv_title_color="#000"
    item:tv_title_margin_left="10dp"
    item:tv_title_text="鬣狗"
    item:v_line_bottom_visibility="true" />
  • 属性介绍

  • 标题有5个属性
<attr name="tv_title_text" format="string" />
<attr name="tv_title_color" format="color" />
<attr name="tv_title_size" format="dimension" />
<attr name="tv_title_margin_left" format="dimension" />
<attr name="tv_title_margin_right" format="dimension" />
  • 副标题有6个属性
<attr name="tv_subtitle_text" format="string" />
<attr name="tv_subtitle_color" format="color" />
<attr name="tv_subtitle_size" format="dimension" />
<attr name="tv_subtitle_margin_left" format="dimension" />
<attr name="tv_subtitle_margin_right" format="dimension" />
<attr name="tv_subtitle_gravity" format="integer">
    <enum name="left" value="0" />
    <enum name="right" value="1" />
    <enum name="bottom" value="2" />
</attr>
  • 左边icon有3个属性
<attr name="iv_left_src" format="reference" />
<attr name="iv_left_size" format="dimension" />
<attr name="iv_left_margin_left" format="dimension" />
  • 右边icon有3个属性
<attr name="iv_right_src" format="reference" />
<attr name="iv_right_size" format="dimension" />
<attr name="iv_right_margin_right" format="dimension" />
  • Switch 2个属性
<attr name="switch_visibility" format="boolean" />
<attr name="switch_checked" format="boolean" />
  • 上、下两条分割线的相关属性
<attr name="v_line_color" format="color" />

<attr name="v_line_top_visibility" format="boolean" />
<attr name="v_line_top_margin_left" format="dimension" />
<attr name="v_line_top_margin_right" format="dimension" />
<attr name="v_line_top_margin_height" format="dimension" />

<attr name="v_line_bottom_visibility" format="boolean" />
<attr name="v_line_bottom_margin_left" format="dimension" />
<attr name="v_line_bottom_margin_right" format="dimension" />
<attr name="v_line_bottom_margin_height" format="dimension" />
  • java中公开的方法
setTitle                    | 设置标题
setSubTitle                 | 设置副标题
setOnCheckedChangeListener  | 设置Switch监听
setChecked                  | 设置Switch
getChecked                  | 获得Switch
高效、精准鬣狗开发而生。更多功能关注Github
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,577评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,452评论 19 139
  • 按照Usher主教的说法,《创世纪》把世界创生定于公元前4004年10月23日上午9时。另一方面,诸如山岳和河流的...
    AwesomeAshe阅读 3,395评论 0 1
  • 我永远记得这样一个黄昏: 学校在放暑假,一群农民工在装修校舍。北京的七月,骄阳似火,热得人无法呼吸。太阳萎下去之后...
    沐儿阅读 5,834评论 25 76
  • 今天晚上雾真大 我把偷下来的月亮送给你吧 你说月亮太暗不闪耀 非要面朝大海我也是没办法 以前你可没这么说 凝固的时...
    伴月眠阅读 2,350评论 0 0