ItemDecoration in Android


ItemDecoration can be drawn to all four sides of RecyclerView items
An ItemDecoration allows the application to add a special drawing and layout offset to specific item views from the adapter’s data set. This can be useful for drawing dividers between items, highlights, visual grouping boundaries and more.

Don’t add dividers as views —It affects performance

<ListView
    android:id="@+id/activity_home_list_view"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:divider="@android:color/black"
    android:dividerHeight="8dp"/>
<LinearLayout android:orientation="vertical">    <LinearLayout android:orientation="horizontal">        <ImageView />        <TextView />    </LinearLayout>    <View
        android:width="match_parent"
        android:height="1dp"
        android:background="#333" /></LinearLayout>

Don’t add dividers as views — It has side effects


Divider moves along with item — looks bad in my opinion

Only the item moves — Divider fades

Don’t add dividers as views — It lacks flexibility


Dividers with an inset for few items

Don’t add dividers as views —Use ItemDecoration

Notes

Comments