# RecyclerView.ItemDecoration

Artifact: [androidx.recyclerview:recyclerview](https://developer.android.com/jetpack/androidx/releases/recyclerview) [View Source](https://cs.android.com/search?q=file:androidx/recyclerview/widget/RecyclerView.java+class:androidx.recyclerview.widget.RecyclerView.ItemDecoration) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***


```
public abstract class RecyclerView.ItemDecoration
```

<br />

Known direct subclasses [DividerItemDecoration](https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration), [ItemTouchHelper](https://developer.android.com/reference/androidx/recyclerview/widget/ItemTouchHelper)

|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration` | DividerItemDecoration is a `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration` that can be used as a divider between items of a `https://developer.android.com/reference/androidx/recyclerview/widget/LinearLayoutManager`. |
| `https://developer.android.com/reference/androidx/recyclerview/widget/ItemTouchHelper` | This is a utility class to add swipe to dismiss and drag \&drop support to RecyclerView. |

*** ** * ** ***

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 `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)` and after the items (in `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#ItemDecoration()()` |

| ### Public methods |
|---|---|
| `void` | `[getItemOffsets](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect,int,androidx.recyclerview.widget.RecyclerView))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Rect.html outRect, int itemPosition, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect,android.view.View,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)` <br /> |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect,android.view.View,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Rect.html outRect, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state )` Retrieve any offsets for the given item. |
| `void` | `[onDraw](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html c, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent)` **This method is deprecated.** Override `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)` <br /> |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html c, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state )` Draw any appropriate decorations into the Canvas supplied to the RecyclerView. |
| `void` | `[onDrawOver](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html c, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent)` **This method is deprecated.** Override `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)` <br /> |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html c, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state )` Draw any appropriate decorations into the Canvas supplied to the RecyclerView. |

## Public constructors

### ItemDecoration

Added in 1.0.0

```
public ItemDecoration()
```

## Public methods

### getItemOffsets

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0) Deprecated in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void [getItemOffsets](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect,int,androidx.recyclerview.widget.RecyclerView))(
    @NonNull Rect outRect,
    int itemPosition,
    @NonNull RecyclerView parent
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect,android.view.View,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)`

### getItemOffsets

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public 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` 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 `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#getChildAdapterPosition(android.view.View)` to get the adapter position of the View.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Rect.html outRect` | Rect to receive the output. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view` | The child view to decorate |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent` | RecyclerView this ItemDecoration is decorating |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state` | The current state of RecyclerView. |

### onDraw

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0) Deprecated in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void [onDraw](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView))(@NonNull Canvas c, @NonNull RecyclerView parent)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Override `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)`

### onDraw

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public 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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html c` | Canvas to draw into |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent` | RecyclerView this ItemDecoration is drawing into |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state` | The current state of RecyclerView |

### onDrawOver

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0) Deprecated in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public void [onDrawOver](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView))(@NonNull Canvas c, @NonNull RecyclerView parent)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Override `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)`

### onDrawOver

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public 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 drawn and will thus appear over the views.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html c` | Canvas to draw into |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent` | RecyclerView this ItemDecoration is drawing into |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state` | The current state of RecyclerView. |