DividerItemDecoration


class DividerItemDecoration : RecyclerView.ItemDecoration


DividerItemDecoration is a RecyclerView.ItemDecoration that can be used as a divider between items of a LinearLayoutManager. It supports both HORIZONTAL and VERTICAL orientations.

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

Summary

Constants

const Int
const Int

Public constructors

DividerItemDecoration(context: Context!, orientation: Int)

Creates a divider RecyclerView.ItemDecoration that can be used with a LinearLayoutManager.

Public functions

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

Retrieve any offsets for the given item.

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

Draw any appropriate decorations into the Canvas supplied to the RecyclerView.

Unit
setDrawable(drawable: Drawable)

Sets the Drawable for this divider.

Unit
setOrientation(orientation: Int)

Sets the orientation for this divider.

Inherited functions

From androidx.recyclerview.widget.RecyclerView.ItemDecoration
Unit
getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView)

This function is deprecated.

Use getItemOffsets

Unit
onDraw(c: Canvas, parent: RecyclerView)

This function is deprecated.

Override onDraw

Unit

This function is deprecated.

Override onDrawOver

Unit

Draw any appropriate decorations into the Canvas supplied to the RecyclerView.

Constants

HORIZONTAL

Added in 1.0.0
const val HORIZONTAL = 0: Int

VERTICAL

Added in 1.0.0
const val VERTICAL = 1: Int

Public constructors

DividerItemDecoration

Added in 1.0.0
DividerItemDecoration(context: Context!, orientation: Int)

Creates a divider RecyclerView.ItemDecoration that can be used with a LinearLayoutManager.

Parameters
context: Context!

Current context, it will be used to access resources.

orientation: Int

Divider orientation. Should be HORIZONTAL or VERTICAL.

Public functions

getDrawable

Added in 1.1.0
fun getDrawable(): Drawable?
Returns
Drawable?

the Drawable 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 to get the adapter position of the View.

Parameters
outRect: Rect!

Rect to receive the output.

view: View!

The child view to decorate

parent: RecyclerView!

RecyclerView this ItemDecoration is decorating

state: 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!

Canvas to draw into

parent: RecyclerView!

RecyclerView this ItemDecoration is drawing into

state: RecyclerView.State!

The current state of RecyclerView

setDrawable

Added in 1.0.0
fun setDrawable(drawable: Drawable): Unit

Sets the Drawable for this divider.

Parameters
drawable: Drawable

Drawable that should be used as a divider.

setOrientation

Added in 1.0.0
fun setOrientation(orientation: Int): Unit

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

Parameters
orientation: Int

HORIZONTAL or VERTICAL