# DividerItemDecoration

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/recyclerview/widget/DividerItemDecoration "View this page in Java")

<br />

```
class DividerItemDecoration : RecyclerView.ItemDecoration
```

<br />

|---|---|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                                                                            |||
| ↳ | [androidx.recyclerview.widget.RecyclerView.ItemDecoration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration) ||
|   | ↳ | [androidx.recyclerview.widget.DividerItemDecoration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration) |

*** ** * ** ***

DividerItemDecoration is a[RecyclerView.ItemDecoration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration)that can be used as a divider between items of a[LinearLayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearLayoutManager). It supports both[HORIZONTAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL())and[VERTICAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL())orientations.  

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

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [HORIZONTAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL())` = 0` |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [VERTICAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL())` = 1`     |

|                                                                                                                                                                                                                                                                                                                            ### Public constructors                                                                                                                                                                                                                                                                                                                             |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DividerItemDecoration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#DividerItemDecoration(android.content.Context,int))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, orientation: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Creates a divider[RecyclerView.ItemDecoration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration)that can be used with a[LinearLayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearLayoutManager). |

|                                      ### Public functions                                      |
|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?` | [getDrawable](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#getDrawable())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [getItemOffsets](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#getItemOffsets(android.graphics.Rect,android.view.View,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State))`(` ` outRect: `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)`!,` ` view: `[View](https://developer.android.com/reference/android/view/View.html)`!,` ` parent: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`!,` ` state: `[RecyclerView.State](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.State)`!` `)` Retrieve any offsets for the given item. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [onDraw](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State))`(c: `[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)`!, parent: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`!, state: `[RecyclerView.State](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.State)`!)` Draw any appropriate decorations into the Canvas supplied to the RecyclerView.                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [setDrawable](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#setDrawable(android.graphics.drawable.Drawable))`(drawable: `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`)` Sets the[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)for this divider.                                                                                                                                                                                                                                                                                                                                                               |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [setOrientation](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#setOrientation(int))`(orientation: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the orientation for this divider.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.recyclerview.widget.RecyclerView.ItemDecoration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration) |-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[getItemOffsets](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect,int,androidx.recyclerview.widget.RecyclerView))~~`(outRect: `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)`, itemPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, parent: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`)` **This function is deprecated.** Use[getItemOffsets](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration#getItemOffsets(android.graphics.Rect,android.view.View,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)) <br /> | | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[onDraw](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView))~~`(c: `[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)`, parent: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`)` **This function is deprecated.** Override[onDraw](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDraw(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)) <br />                                                                                                                                             | | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[onDrawOver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView))~~`(c: `[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)`, parent: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`)` **This function is deprecated.** Override[onDrawOver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State)) <br />                                                                                                                             | | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onDrawOver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration#onDrawOver(android.graphics.Canvas,androidx.recyclerview.widget.RecyclerView,androidx.recyclerview.widget.RecyclerView.State))`(c: `[Canvas](https://developer.android.com/reference/android/graphics/Canvas.html)`, parent: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`, state: `[RecyclerView.State](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.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)  

```
const val HORIZONTAL = 0: Int
```  

### VERTICAL

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

```
const val VERTICAL = 1: Int
```  

## Public constructors

### DividerItemDecoration

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

```
DividerItemDecoration(context: Context!, orientation: Int)
```

Creates a divider[RecyclerView.ItemDecoration](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemDecoration)that can be used with a[LinearLayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/LinearLayoutManager).  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!` | Current context, it will be used to access resources.                                                                                                                                                                                                                                 |
| `orientation: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)    | Divider orientation. Should be[HORIZONTAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL())or[VERTICAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL()). |

## Public functions

### getDrawable

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

```
fun getDrawable(): Drawable?
```  

|                                            Returns                                             |
|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
| [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?` | the[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)for this divider. |

### getItemOffsets

```
fun getItemOffsets(
    outRect: Rect!,
    view: View!,
    parent: RecyclerView!,
    state: RecyclerView.State!
): Unit
```

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

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

### onDraw

```
fun onDraw(c: Canvas!, parent: RecyclerView!, state: RecyclerView.State!): Unit
```

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

### setDrawable

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

```
fun setDrawable(drawable: Drawable): Unit
```

Sets the[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)for this divider.  

|                                               Parameters                                                |
|---------------------------------------------------------------------------------------------------------|--------------------------------------------|
| `drawable: `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) | 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)  

```
fun setOrientation(orientation: Int): Unit
```

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

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `orientation: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [HORIZONTAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#HORIZONTAL())or[VERTICAL](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DividerItemDecoration#VERTICAL()) |