-
先看下需求溉跃,下圖是
設(shè)置-開(kāi)發(fā)者選項(xiàng)
里面的截圖,里面有四種布局十减,不難看出他們有共同點(diǎn)栈幸,比如Title的樣式是一樣的,都有分割線等等帮辟。
設(shè)置-開(kāi)發(fā)者選項(xiàng).png
-
鬣狗快速開(kāi)發(fā)庫(kù)中有一個(gè)自定義控件-MenuItemView速址。可以很好的實(shí)現(xiàn)上面的需求由驹。
MenuItemView效果圖
-
舉個(gè)粒子
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" />
-
屬性介紹
-
標(biāo)題有5個(gè)屬性
<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" />
-
副標(biāo)題有6個(gè)屬性
<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個(gè)屬性
<attr name="iv_left_src" format="reference" />
<attr name="iv_left_size" format="dimension" />
<attr name="iv_left_margin_left" format="dimension" />
-
右邊icon有3個(gè)屬性
<attr name="iv_right_src" format="reference" />
<attr name="iv_right_size" format="dimension" />
<attr name="iv_right_margin_right" format="dimension" />
-
Switch 2個(gè)屬性
<attr name="switch_visibility" format="boolean" />
<attr name="switch_checked" format="boolean" />
-
上芍锚、下兩條分割線的相關(guān)屬性
<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中公開(kāi)的方法
setTitle | 設(shè)置標(biāo)題
setSubTitle | 設(shè)置副標(biāo)題
setOnCheckedChangeListener | 設(shè)置Switch監(jiān)聽(tīng)
setChecked | 設(shè)置Switch
getChecked | 獲得Switch