public abstract class RecyclerViewItemDecoration extends RecyclerView.ItemDecoration
RecyclerView.ItemDecoration implementation that is used as base class by all item
decorations from the Recycler library and is also encouraged to be used as base class by custom
decoration implementations.
ItemDecoration Attributes
noneRecyclerView.addItemDecoration(RecyclerView.ItemDecoration)| Modifier and Type | Class and Description |
|---|---|
static interface |
RecyclerViewItemDecoration.Precondition
Precondition represents a simple check which is performed by an item decoration before its
decoration logic is performed for a specific item view.
|
| Constructor and Description |
|---|
RecyclerViewItemDecoration()
Same as
RecyclerViewItemDecoration(Context) with null context. |
RecyclerViewItemDecoration(Context context)
Same as
RecyclerViewItemDecoration(Context, AttributeSet) with null attrs. |
RecyclerViewItemDecoration(Context context,
AttributeSet attrs)
Same as
RecyclerViewItemDecoration(Context, AttributeSet, int) with 0
defStyleAttr. |
RecyclerViewItemDecoration(Context context,
AttributeSet attrs,
int defStyleAttr)
Same as
RecyclerViewItemDecoration(Context, AttributeSet, int, int) with 0
defStyleRes. |
RecyclerViewItemDecoration(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes)
Creates a new instance of RecyclerViewItemDecoration for the given context.
|
| Modifier and Type | Method and Description |
|---|---|
RecyclerViewItemDecoration.Precondition |
getPrecondition()
Returns the precondition specified for this decoration.
|
void |
setPrecondition(RecyclerViewItemDecoration.Precondition precondition)
Specifies a precondition that should be checked by this decoration for each item view before
it is decorated.
|
void |
setSkipFirst(boolean skip)
Sets a boolean flag indicating whether this decoration should be skipped for the first item
from data set of the associated
RecyclerView. |
void |
setSkipLast(boolean skip)
Sets a boolean flag indicating whether this decoration should be skipped for the last item
from data set of the associated
RecyclerView. |
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.
|
boolean |
skipsFirst()
Checks whether this decoration is skipped for the first item.
|
boolean |
skipsLast()
Checks whether this decoration is skipped for the last item.
|
getItemOffsets, getItemOffsets, onDraw, onDraw, onDrawOver, onDrawOverpublic RecyclerViewItemDecoration()
RecyclerViewItemDecoration(Context) with null context.public RecyclerViewItemDecoration(@Nullable Context context)
RecyclerViewItemDecoration(Context, AttributeSet) with null attrs.public RecyclerViewItemDecoration(@Nullable Context context, @Nullable AttributeSet attrs)
RecyclerViewItemDecoration(Context, AttributeSet, int) with 0
defStyleAttr.public RecyclerViewItemDecoration(@Nullable Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr)
RecyclerViewItemDecoration(Context, AttributeSet, int, int) with 0
defStyleRes.public RecyclerViewItemDecoration(@Nullable Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes 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 setSkipFirst(boolean skip)
RecyclerView.
Default value: false
skip - True to not apply this decoration for the first item, false to
apply it.skipsFirst(),
setSkipLast(boolean),
setPrecondition(Precondition)public boolean skipsFirst()
True if this decoration is not applied for the first item, false if
it is.setSkipFirst(boolean)public void setSkipLast(boolean skip)
RecyclerView.
Default value: false
skip - True to not apply this decoration for the last item, false to
apply it.skipsFirst(),
setSkipFirst(boolean),
setPrecondition(Precondition)public boolean skipsLast()
True if this decoration is not applied for the last item, false if
it is.setSkipLast(boolean)public final void setPrecondition(@NonNull RecyclerViewItemDecoration.Precondition precondition)
This precondition may be used in order to perform more item specific decoration logic.
precondition - The desired precondition which should be checked for each item view
of the parent recycler view before it is decorated.getPrecondition(),
setSkipFirst(boolean),
setSkipLast(boolean)@NonNull public final RecyclerViewItemDecoration.Precondition getPrecondition()
RecyclerViewItemDecoration.Precondition.EMPTY
instance.setPrecondition(Precondition)protected boolean shouldDecorate(@NonNull RecyclerView parent, @NonNull RecyclerView.State state)
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.
parent - The RecyclerView into which is this decoration added.state - Current state of the parent RecyclerView.True if decorating should be performed, false otherwise.