-
public abstract class RecyclerView.ItemDecoration
An ItemDecoration allows the application to add a special drawing and layout offsetto specific item views from the adapter's data set. This can be useful for drawing dividersbetween items, highlights, visual grouping boundaries and more.
All ItemDecorations are drawn in the order they were added, before the itemviews (in onDraw() and after the items (in onDrawOver.
-
-
Method Summary
Modifier and Type Method Description void
onDraw(@NonNull() Canvas c, @NonNull() RecyclerView parent, @NonNull() 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. void
onDraw(@NonNull() Canvas c, @NonNull() RecyclerView parent)
void
onDrawOver(@NonNull() Canvas c, @NonNull() RecyclerView parent, @NonNull() 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 drawnand will thus appear over the views. void
onDrawOver(@NonNull() Canvas c, @NonNull() RecyclerView parent)
void
getItemOffsets(@NonNull() Rect outRect, int itemPosition, @NonNull() RecyclerView parent)
void
getItemOffsets(@NonNull() Rect outRect, @NonNull() View view, @NonNull() RecyclerView parent, @NonNull() RecyclerView.State state)
Retrieve any offsets for the given item. -
-
Method Detail
-
onDraw
void onDraw(@NonNull() Canvas c, @NonNull() RecyclerView parent, @NonNull() 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 intoparent
- RecyclerView this ItemDecoration is drawing intostate
- The current state of RecyclerView
-
onDraw
@Deprecated() void onDraw(@NonNull() Canvas c, @NonNull() RecyclerView parent)
-
onDrawOver
void onDrawOver(@NonNull() Canvas c, @NonNull() RecyclerView parent, @NonNull() 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 drawnand will thus appear over the views.
- Parameters:
c
- Canvas to draw intoparent
- RecyclerView this ItemDecoration is drawing intostate
- The current state of RecyclerView.
-
onDrawOver
@Deprecated() void onDrawOver(@NonNull() Canvas c, @NonNull() RecyclerView parent)
-
getItemOffsets
@Deprecated() void getItemOffsets(@NonNull() Rect outRect, int itemPosition, @NonNull() RecyclerView parent)
-
getItemOffsets
void getItemOffsets(@NonNull() Rect outRect, @NonNull() View view, @NonNull() RecyclerView parent, @NonNull() RecyclerView.State state)
Retrieve any offsets for the given item. Each field of
outRect
specifiesthe 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 setall four fields of
outRect
(left, top, right, bottom) to zerobefore returning.If you need to access Adapter for additional data, you can call getChildAdapterPosition to get the adapter position of theView.
- Parameters:
outRect
- Rect to receive the output.view
- The child view to decorateparent
- RecyclerView this ItemDecoration is decoratingstate
- The current state of RecyclerView.
-
-
-
-