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 |
|
|---|---|
static final int |
HORIZONTAL = 0 |
static final int |
VERTICAL = 1 |
Public constructors |
|---|
DividerItemDecoration(Context context, int orientation)Creates a divider |
Public methods |
|
|---|---|
@Nullable Drawable |
|
void |
getItemOffsets(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(@NonNull Drawable drawable)Sets the |
void |
setOrientation(int orientation)Sets the orientation for this divider. |
Inherited methods |
||||||||
|---|---|---|---|---|---|---|---|---|
|
Constants
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. |
int orientation |
Divider orientation. Should be |
Public methods
getItemOffsets
public 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 to get the adapter position of the View.
| Parameters | |
|---|---|
Rect outRect |
Rect to receive the output. |
View view |
The child view to decorate |
RecyclerView parent |
RecyclerView this ItemDecoration is decorating |
RecyclerView.State state |
The current state of RecyclerView. |
onDraw
public 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 | |
|---|---|
Canvas c |
Canvas to draw into |
RecyclerView parent |
RecyclerView this ItemDecoration is drawing into |
RecyclerView.State state |
The current state of RecyclerView |
setDrawable
public void setDrawable(@NonNull Drawable drawable)
Sets the Drawable for this divider.
setOrientation
public void setOrientation(int orientation)
Sets the orientation for this divider. This should be called if RecyclerView.LayoutManager changes orientation.
| Parameters | |
|---|---|
int orientation |