public class ItemDividerDecoration extends RecyclerViewItemDecoration
RecyclerViewItemDecoration implementation that may be used to draw a divider
(drawable or color), vertically or horizontally, between items displayed in a RecyclerView
widget.
ItemDividerDecoration Attributes
noneRecyclerView#addItemDecoration(RecyclerView.ItemDecoration)| Modifier and Type | Class and Description |
|---|---|
static interface |
ItemDividerDecoration.Orientation
Defines an annotation for determining allowed orientations for
ItemDividerDecoration. |
| Modifier and Type | Field and Description |
|---|---|
static int |
HORIZONTAL
Horizontal orientation flag copied from
LinearLayout.HORIZONTAL for convenience. |
static int |
VERTICAL
Vertical orientation flag copied from
LinearLayout.VERTICAL for convenience. |
| Constructor and Description |
|---|
ItemDividerDecoration()
Same as
ItemDividerDecoration(Context) with null context. |
ItemDividerDecoration(android.content.Context context)
Same as
ItemDividerDecoration(Context, AttributeSet) with null attrs. |
ItemDividerDecoration(android.content.Context context,
android.util.AttributeSet attrs)
Same as
ItemDividerDecoration(Context, AttributeSet, int) with 0 defStyleAttr. |
ItemDividerDecoration(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
Same as
ItemDividerDecoration(Context, AttributeSet, int, int) with 0 defStyleRes. |
ItemDividerDecoration(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Creates a new instance of ItemDividerDecoration for the given context.
|
ItemDividerDecoration(int orientation,
android.graphics.drawable.Drawable divider)
Creates a new instance of ItemDividerDecoration with the specified orientation
and divider.
|
| Modifier and Type | Method and Description |
|---|---|
android.graphics.drawable.Drawable |
getDivider()
Returns the divider drawable that is drawn by this decoration between items.
|
int |
getDividerThickness()
Returns the thickness in which should be the divider drawn between items.
|
void |
getItemOffsets(android.graphics.Rect rect,
android.view.View view,
RecyclerView parent,
RecyclerView.State state) |
int |
getOrientation()
Returns the orientation in which is the divider drawable drawn between items.
|
void |
onDraw(android.graphics.Canvas canvas,
RecyclerView parent,
RecyclerView.State state) |
protected void |
onDrawHorizontally(android.graphics.Canvas canvas,
RecyclerView parent,
RecyclerView.State state)
Called from
#onDrawOver(Canvas, RecyclerView, RecyclerView.State) in order to draw
this decoration in vertical orientation. |
protected void |
onDrawVertically(android.graphics.Canvas canvas,
RecyclerView parent,
RecyclerView.State state)
Called from
#onDrawOver(Canvas, RecyclerView, RecyclerView.State) in order to draw
this decoration in horizontal orientation. |
void |
setDivider(android.graphics.drawable.Drawable divider)
Sets a drawable of the divider to be drawn between items of the associated
RecyclerView
in the orientation specified for this decoration. |
void |
setDividerThickness(int thickness)
Sets a thickness in which should be the divider specified for this decoration drawn.
|
void |
setOrientation(int orientation)
Sets an orientation in which should be the divider specified for this decoration drawn.
|
protected boolean |
shouldDecorate(RecyclerView parent,
RecyclerView.State state)
Checks whether any subsequent decoration algorithm should be applied by this decoration for
the given parent RecyclerView and its current state.
|
setSkipFirst, setSkipLast, skipsFirst, skipsLastpublic static final int HORIZONTAL
LinearLayout.HORIZONTAL for convenience.public static final int VERTICAL
LinearLayout.VERTICAL for convenience.public ItemDividerDecoration()
ItemDividerDecoration(Context) with null context.public ItemDividerDecoration(int orientation,
android.graphics.drawable.Drawable divider)
orientation - The desired orientation in which should be the divider drawn. One of
orientation defined by @Orientation annotation.divider - Drawable of the desired divider to be drawn. If this is a ColorDrawable
the divider's thickness need to be specified via setDividerThickness(int)
as the color drawable does not have its intrinsic dimensions specified.setOrientation(int),
setDivider(Drawable)public ItemDividerDecoration(android.content.Context context)
ItemDividerDecoration(Context, AttributeSet) with null attrs.public ItemDividerDecoration(android.content.Context context,
android.util.AttributeSet attrs)
ItemDividerDecoration(Context, AttributeSet, int) with 0 defStyleAttr.public ItemDividerDecoration(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr)
ItemDividerDecoration(Context, AttributeSet, int, int) with 0 defStyleRes.public ItemDividerDecoration(android.content.Context context,
android.util.AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
context - Context in which will be the new decoration presented.attrs - Set of Xml attributes used to configure the new instance of this decoration.defStyleAttr - An attribute which contains a reference to a default style resource for
this decoration within a theme of the given context.defStyleRes - Resource id of the default style for the new decoration.public void setOrientation(int orientation)
Default value: VERTICAL
orientation - The desired orientation. Should be one of orientations defined by
@Orientation annotation.getOrientation()public int getOrientation()
setOrientation(int)public void setDivider(android.graphics.drawable.Drawable divider)
RecyclerView
in the orientation specified for this decoration.
Note that calling this method will reset any thickness value specified via
setDividerThickness(int) before and the thickness of the given divider drawable will
be used instead depending on the orientation specified for this decoration.
divider - The desired divider drawable. May be null to to not draw any divider.getDivider()public android.graphics.drawable.Drawable getDivider()
null if no divider has been specified.setDivider(Drawable)public void setDividerThickness(int thickness)
Note that calling this method will override the intrinsic thickness obtained form the divider
drawable when setDivider(Drawable) has been called.
thickness - The desired thickness. May be 0 to not draw the divider.getDividerThickness()public int getDividerThickness()
setDividerThickness(int)public void getItemOffsets(android.graphics.Rect rect,
android.view.View view,
RecyclerView parent,
RecyclerView.State state)
public void onDraw(android.graphics.Canvas canvas,
RecyclerView parent,
RecyclerView.State state)
protected boolean shouldDecorate(RecyclerView parent,
RecyclerView.State state)
RecyclerViewItemDecoration
This implementation checks whether the given RecyclerView has its RecyclerView.LayoutManager
specified by RecyclerView.getLayoutManager() != null and if there are any items to be
decorated by RecyclerView.State.getItemCount() > 0. If both conditions are met, this
method returns true, if not, false is returned.
shouldDecorate in class RecyclerViewItemDecorationparent - The RecyclerView into which is this decoration added.state - Current state of the parent RecyclerView.True if decorating should be performed, false otherwise.protected void onDrawHorizontally(android.graphics.Canvas canvas,
RecyclerView parent,
RecyclerView.State state)
#onDrawOver(Canvas, RecyclerView, RecyclerView.State) in order to draw
this decoration in vertical orientation.canvas - Canvas on which to draw.parent - RecyclerView into which is this decoration added.state - Current state of the parent RecyclerView.protected void onDrawVertically(android.graphics.Canvas canvas,
RecyclerView parent,
RecyclerView.State state)
#onDrawOver(Canvas, RecyclerView, RecyclerView.State) in order to draw
this decoration in horizontal orientation.canvas - Canvas on which to draw.parent - RecyclerView into which is this decoration added.state - Current state of the parent RecyclerView.