Tuesday, September 6, 2016

Android ListView Attributes (divider, dividerHeight)




1. Attributes of the Android ListView.

Attributes Description
divider Drawable or color to draw between list items.
dividerHeight Height of the divider.
entries Reference to an array resource that will populate the ListView.
footerDividersEnabled When set to false, the ListView will not draw the divider before each footer view.
headerDividersEnabled When set to false, the ListView will not draw the divider after each header view.
cacheColorHint Indicates that this list will always be drawn on top of solid, single-color opaque background.
choiceMode Defines the choice behavior for the view.
drawSelectorOnTop When set to true, the selector will be drawn over the selected item.
fastScrollEnabled Enables the fast scroll thumb that can be dragged to quickly scroll through the list.
listSelector Drawable used to indicate the currently selected item in the list.
scrollingCache When set to true, the list uses a drawing cache during scrolling.
smoothScrollbar When set to true, the list will use a more refined calculation method based on the pixels height of the items visible on screen.
stackFromBottom Used by ListView and GridView to stack their content from the bottom.
textFilterEnabled When set to true, the list will filter results as the user types.
transcriptMode Sets the transcript mode for the list.

2. Drawing the divider between ListView items. (divider, dividerHeight)

Usually, when multiple items are added to the ListView, the divider with gray color is drawn between items. By the way, What should I do if I want to change the divider's style(color, height or image) ?
It is to use "divider" attribute.
  * android:divider - Drawable or color to draw between list items.
        > Color (#rgb, #argb, #rrggbb, "#aarrggbb")
        > Drawable (@drawable/xxx)
        > Another resource (?android:attr/yyy)
Also, the divider's height can be adjusted by using "dividerHeight" attribute.
  * android:dividerHeight - set height of the divider.
        > Dimension (sp, px, dp, in, mm)
Examples of "divider" and "dividerHeight" are shown below.

2.1 Default Divider. ("divider" attribute is not used)

    <ListView
        android:id="@+id/listview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
ListView Default Divider



2.2 Color Divider. (Green and 2dp height)

    <ListView
        android:id="@+id/listview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#00FF00"
        android:dividerHeight="2dp" />
ListView Color Divider

2.3 Drawable Divider.

    <ListView
        android:id="@+id/listview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@drawable/dotted_divider" />
ListView Drawable Divider

2.4 Transparent Divider. (Set alpha to "0x00")

    <ListView
        android:id="@+id/listview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#00000000" />
ListView Transparent Divider

3. References.

.END.

No comments:

Post a Comment