-
public class DividerItemDecoration extends 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);
-
-
Field Summary
Fields Modifier and Type Field Description public final static int
HORIZONTAL
public final static int
VERTICAL
-
Constructor Summary
Constructors Constructor Description DividerItemDecoration(Context context, int orientation)
Creates a divider RecyclerView.ItemDecoration that can be used with a LinearLayoutManager.
-
Method Summary
Modifier and Type Method Description void
setOrientation(int orientation)
Sets the orientation for this divider. void
setDrawable(@NonNull() Drawable drawable)
Sets the Drawable for this divider. Drawable
getDrawable()
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. void
getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
Retrieve any offsets for the given item. -
-
Constructor Detail
-
DividerItemDecoration
DividerItemDecoration(Context context, int orientation)
Creates a divider RecyclerView.ItemDecoration that can be used with a LinearLayoutManager.- Parameters:
context
- Current context, it will be used to access resources.orientation
- Divider orientation.
-
-
Method Detail
-
setOrientation
void setOrientation(int orientation)
Sets the orientation for this divider. This should be called if RecyclerView.LayoutManager changes orientation.
- Parameters:
orientation
- HORIZONTAL or VERTICAL
-
setDrawable
void setDrawable(@NonNull() Drawable drawable)
Sets the Drawable for this divider.
- Parameters:
drawable
- Drawable that should be used as a divider.
-
getDrawable
@Nullable() Drawable getDrawable()
-
onDraw
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 to draw intoparent
- RecyclerView this ItemDecoration is drawing intostate
- The current state of RecyclerView
-
getItemOffsets
void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
Retrieve any offsets for the given item. Each field of
outRect
specifiesthe 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 setall four fields of
outRect
(left, top, right, bottom) to zerobefore returning.If you need to access Adapter for additional data, you can call getChildAdapterPosition to get the adapter position of theView.
- Parameters:
outRect
- Rect to receive the output.view
- The child view to decorateparent
- RecyclerView this ItemDecoration is decoratingstate
- The current state of RecyclerView.
-
-
-
-