# DividerItemDecoration

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

*** ** * ** ***


```
public class DividerItemDecoration extends RecyclerView.ItemDecoration
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.recyclerview.widget.RecyclerView.ItemDecoration](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration) ||
|   | ↳ | [androidx.recyclerview.widget.DividerItemDecoration](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`. It supports both `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL()` and `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL()` orientations.

```
    mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
            mLayoutManager.getOrientation());
    recyclerView.addItemDecoration(mDividerItemDecoration);
```

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL() = 0` |
| `static final int` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL() = 1` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#DividerItemDecoration(android.content.Context,int)(https://developer.android.com/reference/android/content/Context.html context, int orientation)` Creates a divider `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration` that can be used with a `https://developer.android.com/reference/androidx/recyclerview/widget/LinearLayoutManager`. |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#getDrawable()()` |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#getItemOffsets(android.graphics.Rect,android.view.View,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)( https://developer.android.com/reference/android/graphics/Rect.html outRect, https://developer.android.com/reference/android/view/View.html view, https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent, https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state )` Retrieve any offsets for the given item. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)(https://developer.android.com/reference/android/graphics/Canvas.html c, https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent, https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state)` Draw any appropriate decorations into the Canvas supplied to the RecyclerView. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#setDrawable(android.graphics.drawable.Drawable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/drawable/Drawable.html drawable)` Sets the `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` for this divider. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#setOrientation(int)(int orientation)` Sets the orientation for this divider. |

| ### Inherited methods |
|---|
| From [androidx.recyclerview.widget.RecyclerView.ItemDecoration](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration) |---|---| | `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` | `[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` | `[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. | |

## Constants

### HORIZONTAL

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

```
public static final int HORIZONTAL = 0
```

### VERTICAL

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

```
public static final int VERTICAL = 1
```

## Public constructors

### DividerItemDecoration

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

```
public DividerItemDecoration(Context context, int orientation)
```

Creates a divider `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ItemDecoration` that can be used with a `https://developer.android.com/reference/androidx/recyclerview/widget/LinearLayoutManager`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | Current context, it will be used to access resources. |
| `int orientation` | Divider orientation. Should be `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL()` or `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL()`. |

## Public methods

### getDrawable

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

```
public @Nullable Drawable getDrawable()
```

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | the `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` for this divider. |

### getItemOffsets

```
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 `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/android/graphics/Rect.html outRect` | Rect to receive the output. |
| `https://developer.android.com/reference/android/view/View.html view` | The child view to decorate |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView parent` | RecyclerView this ItemDecoration is decorating |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.State state` | The current state of RecyclerView. |

### onDraw

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

### setDrawable

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

```
public void setDrawable(@NonNull Drawable drawable)
```

Sets the `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` for this divider.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/drawable/Drawable.html drawable` | Drawable that should be used as a divider. |

### setOrientation

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

```
public void setOrientation(int orientation)
```

Sets the orientation for this divider. This should be called if `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` changes orientation.

| Parameters |
|---|---|
| `int orientation` | `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL()` or `https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL()` |