Skip to content

Most visited

Recently visited

navigation
added in version 25.1.0
belongs to Maven artifact com.android.support:recyclerview-v7:27.0.0

DividerItemDecoration

public class DividerItemDecoration
extends RecyclerView.ItemDecoration

java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.ItemDecoration
     ↳ android.support.v7.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

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

From class android.support.v7.widget.RecyclerView.ItemDecoration
From class java.lang.Object

Constants

HORIZONTAL

added in version 25.1.0
int HORIZONTAL

Constant Value: 0 (0x00000000)

VERTICAL

added in version 25.1.0
int VERTICAL

Constant Value: 1 (0x00000001)

Public constructors

DividerItemDecoration

added in version 25.1.0
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.

Public methods

getItemOffsets

added in version 25.1.0
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 getChildAdapterPosition(View) 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

added in version 25.1.0
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
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 version 25.1.0
void setDrawable (Drawable drawable)

Sets the Drawable for this divider.

Parameters
drawable Drawable: Drawable that should be used as a divider.

setOrientation

added in version 25.1.0
void setOrientation (int orientation)

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

Parameters
orientation int: HORIZONTAL or VERTICAL

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)