public abstract class

RecyclerView.ItemDecoration

extends java.lang.Object

 java.lang.Object

↳androidx.recyclerview.widget.RecyclerView.ItemDecoration

Subclasses:

DividerDecoration, BottomOffsetDecoration, ItemSpacingDecoration, TopOffsetDecoration, DividerItemDecoration, ItemTouchHelper

Overview

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.

All ItemDecorations are drawn in the order they were added, before the item views (in onDraw() and after the items (in RecyclerView.ItemDecoration.onDrawOver(Canvas, RecyclerView, RecyclerView.State).

Summary

Constructors
publicItemDecoration()

Methods
public voidgetItemOffsets(Rect outRect, int itemPosition, RecyclerView parent)

public voidgetItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)

Retrieve any offsets for the given item.

public voidonDraw(Canvas c, RecyclerView parent)

public voidonDraw(Canvas c, RecyclerView parent, RecyclerView.State state)

Draw any appropriate decorations into the Canvas supplied to the RecyclerView.

public voidonDrawOver(Canvas c, RecyclerView parent)

public voidonDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)

Draw any appropriate decorations into the Canvas supplied to the RecyclerView.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public ItemDecoration()

Methods

public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state)

Draw any appropriate decorations into the Canvas supplied to the RecyclerView. Any content drawn by this method will be drawn before the item views are drawn, and will thus appear underneath the views.

Parameters:

c: Canvas to draw into
parent: RecyclerView this ItemDecoration is drawing into
state: The current state of RecyclerView

public void onDraw(Canvas c, RecyclerView parent)

Deprecated: Override RecyclerView.ItemDecoration.onDraw(Canvas, RecyclerView, RecyclerView.State)

public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)

Draw any appropriate decorations into the Canvas supplied to the RecyclerView. Any content drawn by this method will be drawn after the item views are drawn and will thus appear over the views.

Parameters:

c: Canvas to draw into
parent: RecyclerView this ItemDecoration is drawing into
state: The current state of RecyclerView.

public void onDrawOver(Canvas c, RecyclerView parent)

Deprecated: Override RecyclerView.ItemDecoration.onDrawOver(Canvas, RecyclerView, RecyclerView.State)

public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent)

Deprecated: Use RecyclerView.ItemDecoration

public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)

Retrieve any offsets for the given item. Each field of outRect specifies the number of pixels that the item view should be inset by, similar to padding or margin. The default implementation sets the bounds of outRect to 0 and returns.

If this ItemDecoration does not affect the positioning of item views, it should set all four fields of outRect (left, top, right, bottom) to zero before returning.

If you need to access Adapter for additional data, you can call RecyclerView.getChildAdapterPosition(View) to get the adapter position of the View.

Parameters:

outRect: Rect to receive the output.
view: The child view to decorate
parent: RecyclerView this ItemDecoration is decorating
state: The current state of RecyclerView.