android set divider padding for preference screen -
i have preferencescreen contain many checkbox , customize refer custom layout bellow :
<?xml version="1.0" encoding="utf-8" ?> <preferencescreen xmlns:android="http://schemas.android.com/apk/res/android"> <checkboxpreference android:summary="checkbox one" android:key="key_one" android:layout="@layout/mylayout" /> <checkboxpreference android:summary="checkbox two" android:key="key_two" android:layout="@layout/mylayout" /> </preferencescreen> mylayout.xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minheight="?android:attr/listpreferreditemheight" android:gravity="center_vertical" android:paddingright="?android:attr/scrollbarsize"> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:minwidth="@dimen/preference_icon_minwidth" android:orientation="horizontal"> <imageview android:id="@+android:id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </linearlayout> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="16dip" android:layout_marginright="8dip" android:layout_margintop="6dip" android:layout_marginbottom="6dip" android:layout_weight="1"> <textview android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:fadingedge="horizontal" /> <textview android:id="@+android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignleft="@android:id/title" android:textappearance="?android:attr/textappearancesmall" android:textcolor="?android:attr/textcolorsecondary" android:maxlines="4" /> </relativelayout> <linearlayout android:id="@+android:id/widget_frame" android:layout_width="wrap_content" android:layout_height="match_parent" android:minwidth="@dimen/preference_widget_width" android:gravity="center" android:orientation="vertical" /> </linearlayout> every thing run fine customize divider between checkbox in prefs activity :
listview list = (listview) findviewbyid(android.r.id.list); list.setdivider(new colordrawable(color.red)); // or other color int list.setdividerheight((5)); list.setverticalscrollbarenabled(false); when want set padding divider :
list.setpadding(0, 0, 0, 0); it set padding view ,
how can set padding divider without affect padding of view .
any appreciated, thanks
to allow preference divider padding
first : add line preference activity lead transparency of android default divider
list.setdivider(new colordrawable(0x00000000)); second : create folder named drawable in res , create on divider.xml below :
<?xml version="1.0" encoding="utf-8" ?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#b22222" /> </shape> third :
add view mylayout.xml below :
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:minheight="?android:attr/listpreferreditemheight" android:gravity="center_vertical" android:paddingright="?android:attr/scrollbarsize"> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center" android:minwidth="@dimen/preference_icon_minwidth" android:orientation="horizontal"> <imageview android:id="@+android:id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </linearlayout> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="16dip" android:layout_marginright="8dip" android:layout_margintop="6dip" android:layout_marginbottom="6dip" android:layout_weight="1"> <textview android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:fadingedge="horizontal" /> <textview android:id="@+android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@android:id/title" android:layout_alignleft="@android:id/title" android:textappearance="?android:attr/textappearancesmall" android:textcolor="?android:attr/textcolorsecondary" android:maxlines="4" /> <view android:id="@+id/divider" android:background="@drawable/divider" android:layout_width="match_parent" android:layout_marginleft="30dp" android:layout_marginright="30dp" android:layout_height="5dp" android:layout_below="@+android:id/summary"/> </relativelayout> <!-- preference should place actual preference widget here. --> <linearlayout android:id="@+android:id/widget_frame" android:layout_width="wrap_content" android:layout_height="match_parent" android:minwidth="@dimen/preference_widget_width" android:gravity="center" android:orientation="vertical" /> the point here add view bellow texts , refer view divider shape in drawable res custom divider can customized need.
hope .
the output below:

Comments
Post a Comment