# MaterialDividerItemDecoration

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/divider/MaterialDividerItemDecoration.java)

*** ** * ** ***


```
public class MaterialDividerItemDecoration
```

<br />

*** ** * ** ***

MaterialDividerItemDecoration is a RecyclerView.ItemDecoration, similar to a androidx.recyclerview.widget.DividerItemDecoration, that can be used as a divider between items of a LinearLayoutManager. It supports both `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#HORIZONTAL()` and `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#VERTICAL()` orientations.

```
    dividerItemDecoration = new MaterialDividerItemDecoration(recyclerView.getContext(),
            layoutManager.getOrientation());
    recyclerView.addItemDecoration(dividerItemDecoration);
```

For more information, see the [component developer guidance](https://github.com/material-components/material-components-android/blob/master/docs/components/Divider.md) and [design guidelines](https://material.io/components/divider/overview).

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#HORIZONTAL()` |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#VERTICAL()` |

| ### Public fields |
|---|---|
| `int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#orientation()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#MaterialDividerItemDecoration(Context,int)(Context context, int orientation)` |
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#MaterialDividerItemDecoration(Context,AttributeSet,int)( Context context, AttributeSet attrs, int orientation )` |
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#MaterialDividerItemDecoration(Context,AttributeSet,int,int)( Context context, AttributeSet attrs, int defStyleAttr, int orientation )` |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerColor()()` Returns the divider color. |
| `int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerInsetEnd()()` Returns the divider's end inset. |
| `int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerInsetStart()()` Returns the divider's start inset. |
| `int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerThickness()()` Returns the thickness set on the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getItemOffsets(Rect,View,RecyclerView,RecyclerView.State)(Rect outRect, View view, RecyclerView parent, State state)` |
| `int` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getOrientation()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#isLastItemDecorated()()` Whether there's a divider after the last item of a RecyclerView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#onDraw(Canvas,RecyclerView,RecyclerView.State)(Canvas canvas, RecyclerView parent, State state)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerColor(int)(int color)` Sets the color of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerColorResource(Context,int)(Context context, int colorId)` Sets the color of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerInsetEnd(int)(int insetEnd)` Sets the end inset of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerInsetEndResource(Context,int)(Context context, int insetEndId)` Sets the end inset of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerInsetStart(int)(int insetStart)` Sets the start inset of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerInsetStartResource(Context,int)(Context context, int insetStartId)` Sets the start inset of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerThickness(int)(int thickness)` Sets the thickness of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerThicknessResource(Context,int)(Context context, int thicknessId)` Sets the thickness of the divider. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setLastItemDecorated(boolean)(boolean lastItemDecorated)` Sets whether the class should draw a divider after the last item of a RecyclerView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setOrientation(int)(int orientation)` Sets the orientation for this divider. |

| ### Protected methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#shouldDrawDivider(int,RecyclerView.Adapter<?>)(int position, Adapter<?> adapter)` Whether a divider should be drawn below the current item that is being drawn. |

## Constants

### HORIZONTAL

```
public static final int HORIZONTAL
```

### VERTICAL

```
public static final int VERTICAL
```

## Public fields

### orientation

```
public int orientation
```

## Public constructors

### MaterialDividerItemDecoration

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

### MaterialDividerItemDecoration

```
public MaterialDividerItemDecoration(
    Context context,
    AttributeSet attrs,
    int orientation
)
```

### MaterialDividerItemDecoration

```
public MaterialDividerItemDecoration(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int orientation
)
```

## Public methods

### getDividerColor

```
public int getDividerColor()
```

Returns the divider color.

ref com.google.android.material.R.styleable#MaterialDivider_dividerColor

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerColor(int)` |   |

### getDividerInsetEnd

```
public int getDividerInsetEnd()
```

Returns the divider's end inset.

ref com.google.android.material.R.styleable#MaterialDivider_dividerInsetEnd

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerInsetEnd(int)` |   |

### getDividerInsetStart

```
public int getDividerInsetStart()
```

Returns the divider's start inset.

ref com.google.android.material.R.styleable#MaterialDivider_dividerInsetStart

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerInsetStart(int)` |   |

### getDividerThickness

```
public int getDividerThickness()
```

Returns the thickness set on the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerThickness

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setDividerThickness(int)` |   |

### getItemOffsets

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

### getOrientation

```
public int getOrientation()
```

### isLastItemDecorated

```
public boolean isLastItemDecorated()
```

Whether there's a divider after the last item of a RecyclerView.

ref com.google.android.material.R.styleable#MaterialDivider_shouldDecorateLastItem

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#setLastItemDecorated(boolean)` |   |

### onDraw

```
public void onDraw(Canvas canvas, RecyclerView parent, State state)
```

### setDividerColor

```
public void setDividerColor(int color)
```

Sets the color of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerColor

| Parameters |
|---|---|
| `int color` | The color to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerColor()` |   |

### setDividerColorResource

```
public void setDividerColorResource(Context context, int colorId)
```

Sets the color of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerColor

| Parameters |
|---|---|
| `int colorId` | The id of the color resource to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerColor()` |   |

### setDividerInsetEnd

```
public void setDividerInsetEnd(int insetEnd)
```

Sets the end inset of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerInsetEnd

| Parameters |
|---|---|
| `int insetEnd` | The end inset to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerInsetEnd()` |   |

### setDividerInsetEndResource

```
public void setDividerInsetEndResource(Context context, int insetEndId)
```

Sets the end inset of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerInsetEnd

| Parameters |
|---|---|
| `int insetEndId` | The id of the inset dimension resource to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerInsetEnd()` |   |

### setDividerInsetStart

```
public void setDividerInsetStart(int insetStart)
```

Sets the start inset of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerInsetStart

| Parameters |
|---|---|
| `int insetStart` | The start inset to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerInsetStart()` |   |

### setDividerInsetStartResource

```
public void setDividerInsetStartResource(Context context, int insetStartId)
```

Sets the start inset of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerInsetStart

| Parameters |
|---|---|
| `int insetStartId` | The id of the inset dimension resource to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerInsetStart()` |   |

### setDividerThickness

```
public void setDividerThickness(int thickness)
```

Sets the thickness of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerThickness

| Parameters |
|---|---|
| `int thickness` | The thickness value to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerThickness()` |   |

### setDividerThicknessResource

```
public void setDividerThicknessResource(Context context, int thicknessId)
```

Sets the thickness of the divider.

ref com.google.android.material.R.styleable#MaterialDivider_dividerThickness

| Parameters |
|---|---|
| `int thicknessId` | The id of the thickness dimension resource to be set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#getDividerThickness()` |   |

### setLastItemDecorated

```
public void setLastItemDecorated(boolean lastItemDecorated)
```

Sets whether the class should draw a divider after the last item of a RecyclerView.

ref com.google.android.material.R.styleable#MaterialDivider_lastItemDecorated

| Parameters |
|---|---|
| `boolean lastItemDecorated` | whether there's a divider after the last item of a recycler view. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#isLastItemDecorated()` |   |

### setOrientation

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

Sets the orientation for this divider. This should be called if RecyclerView.LayoutManager changes orientation.

A `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#HORIZONTAL()` orientation will draw a vertical divider, and a `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#VERTICAL()` orientation a horizontal divider.

| Parameters |
|---|---|
| `int orientation` | The orientation of the RecyclerView this divider is associated with: `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#HORIZONTAL()` or `https://developer.android.com/reference/com/google/android/material/divider/MaterialDividerItemDecoration#VERTICAL()` |

## Protected methods

### shouldDrawDivider

```
protected boolean shouldDrawDivider(int position, Adapter<?> adapter)
```

Whether a divider should be drawn below the current item that is being drawn.

Note: if lasItemDecorated is false, the divider below the last item will never be drawn even if this method returns true.

| Parameters |
|---|---|
| `int position` | the position of the current item being drawn. |
| `Adapter<?> adapter` | the RecyclerView.Adapter associated with the item being drawn. |