DividerItemDecoration

public class DividerItemDecoration
extends RecyclerView.ItemDecoration

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.ItemDecoration
     ↳ androidx.recyclerview.widget.DividerItemDecoration


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

int HORIZONTAL

int VERTICAL

Public constructors

DividerItemDecoration(Context context, int orientation)

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

Public methods

Drawable getDrawable()
void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)

Retrieve any offsets for the given item.

void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state)

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

void setDrawable(Drawable drawable)

Sets the Drawable for this divider.

void setOrientation(int orientation)

Sets the orientation for this divider.

Inherited methods

Constants

HORIZONTAL

public static final int HORIZONTAL

Constant Value: 0 (0x00000000)

VERTICAL

public static final int VERTICAL

Constant Value: 1 (0x00000001)

Public constructors

DividerItemDecoration

public DividerItemDecoration (Context context, 
                int orientation)

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.