belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1
DefaultItemAnimator
public
class
DefaultItemAnimator
extends SimpleItemAnimator
java.lang.Object | |||
↳ | android.support.v7.widget.RecyclerView.ItemAnimator | ||
↳ | android.support.v7.widget.SimpleItemAnimator | ||
↳ | android.support.v7.widget.DefaultItemAnimator |
This implementation of RecyclerView.ItemAnimator
provides basic
animations on remove, add, and move events that happen to the items in
a RecyclerView. RecyclerView uses a DefaultItemAnimator by default.
Summary
Inherited constants |
---|
From
class
android.support.v7.widget.RecyclerView.ItemAnimator
|
Public constructors | |
---|---|
DefaultItemAnimator()
|
Public methods | |
---|---|
boolean
|
animateAdd(RecyclerView.ViewHolder holder)
Called when an item is added to the RecyclerView. |
boolean
|
animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY)
Called when an item is changed in the RecyclerView, as indicated by a call to
|
boolean
|
animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY)
Called when an item is moved in the RecyclerView. |
boolean
|
animateRemove(RecyclerView.ViewHolder holder)
Called when an item is removed from the RecyclerView. |
boolean
|
canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder, List<Object> payloads)
When an item is changed, ItemAnimator can decide whether it wants to re-use the same ViewHolder for animations or RecyclerView should create a copy of the item and ItemAnimator will use both to run the animation (e.g.
If the payload list is not empty, DefaultItemAnimator returns |
void
|
endAnimation(RecyclerView.ViewHolder item)
Method called when an animation on a view should be ended immediately. |
void
|
endAnimations()
Method called when all item animations should be ended immediately. |
boolean
|
isRunning()
Method which returns whether there are any item animations currently running. |
void
|
runPendingAnimations()
Called when there are pending animations waiting to be started. |
Inherited methods | |
---|---|
From
class
android.support.v7.widget.SimpleItemAnimator
| |
From
class
android.support.v7.widget.RecyclerView.ItemAnimator
| |
From
class
java.lang.Object
|
Public constructors
Public methods
animateAdd
boolean animateAdd (RecyclerView.ViewHolder holder)
Called when an item is added to the RecyclerView. Implementors can choose
whether and how to animate that change, but must always call
dispatchAddFinished(ViewHolder)
when done, either
immediately (if no animation will occur) or after the animation actually finishes.
The return value indicates whether an animation has been set up and whether the
ItemAnimator's runPendingAnimations()
method should be called at the
next opportunity. This mechanism allows ItemAnimator to set up individual animations
as separate calls to animateAdd()
,
animateMove()
,
animateRemove()
, and
animateChange(ViewHolder, ViewHolder, int, int, int, int)
come in one by one,
then start the animations together in the later call to runPendingAnimations()
.
This method may also be called for appearing items which were already in the RecyclerView, but for which the system does not have enough information to animate them into view. In that case, the default animation for adding items is run on those items as well.
Parameters | |
---|---|
holder |
RecyclerView.ViewHolder : The item that is being added. |
Returns | |
---|---|
boolean |
true if a later call to runPendingAnimations() is requested,
false otherwise.
|
animateChange
boolean animateChange (RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY)
Called when an item is changed in the RecyclerView, as indicated by a call to
notifyItemChanged(int)
or
notifyItemRangeChanged(int, int)
.
Implementers can choose whether and how to animate changes, but must always call
dispatchChangeFinished(ViewHolder, boolean)
for each non-null distinct ViewHolder,
either immediately (if no animation will occur) or after the animation actually finishes.
If the oldHolder
is the same ViewHolder as the newHolder
, you must call
dispatchChangeFinished(ViewHolder, boolean)
once and only once. In that case, the
second parameter of dispatchChangeFinished
is ignored.
The return value indicates whether an animation has been set up and whether the
ItemAnimator's runPendingAnimations()
method should be called at the
next opportunity. This mechanism allows ItemAnimator to set up individual animations
as separate calls to animateAdd()
,
animateMove()
,
animateRemove()
, and
animateChange(ViewHolder, ViewHolder, int, int, int, int)
come in one by one,
then start the animations together in the later call to runPendingAnimations()
.
Parameters | |
---|---|
oldHolder |
RecyclerView.ViewHolder : The original item that changed. |
newHolder |
RecyclerView.ViewHolder : The new item that was created with the changed content. Might be null |
fromX |
int : Left of the old view holder |
fromY |
int : Top of the old view holder |
toX |
int : Left of the new view holder |
toY |
int : Top of the new view holder |
Returns | |
---|---|
boolean |
true if a later call to runPendingAnimations() is requested,
false otherwise.
|
animateMove
boolean animateMove (RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY)
Called when an item is moved in the RecyclerView. Implementors can choose
whether and how to animate that change, but must always call
dispatchMoveFinished(ViewHolder)
when done, either
immediately (if no animation will occur) or after the animation actually finishes.
The return value indicates whether an animation has been set up and whether the
ItemAnimator's runPendingAnimations()
method should be called at the
next opportunity. This mechanism allows ItemAnimator to set up individual animations
as separate calls to animateAdd()
,
animateMove()
,
animateRemove()
, and
animateChange(ViewHolder, ViewHolder, int, int, int, int)
come in one by one,
then start the animations together in the later call to runPendingAnimations()
.
Parameters | |
---|---|
holder |
RecyclerView.ViewHolder : The item that is being moved. |
fromX |
int |
fromY |
int |
toX |
int |
toY |
int |
Returns | |
---|---|
boolean |
true if a later call to runPendingAnimations() is requested,
false otherwise.
|
animateRemove
boolean animateRemove (RecyclerView.ViewHolder holder)
Called when an item is removed from the RecyclerView. Implementors can choose
whether and how to animate that change, but must always call
dispatchRemoveFinished(ViewHolder)
when done, either
immediately (if no animation will occur) or after the animation actually finishes.
The return value indicates whether an animation has been set up and whether the
ItemAnimator's runPendingAnimations()
method should be called at the
next opportunity. This mechanism allows ItemAnimator to set up individual animations
as separate calls to animateAdd()
,
animateMove()
,
animateRemove()
, and
animateChange(ViewHolder, ViewHolder, int, int, int, int)
come in one by one,
then start the animations together in the later call to runPendingAnimations()
.
This method may also be called for disappearing items which continue to exist in the RecyclerView, but for which the system does not have enough information to animate them out of view. In that case, the default animation for removing items is run on those items as well.
Parameters | |
---|---|
holder |
RecyclerView.ViewHolder : The item that is being removed. |
Returns | |
---|---|
boolean |
true if a later call to runPendingAnimations() is requested,
false otherwise.
|
canReuseUpdatedViewHolder
boolean canReuseUpdatedViewHolder (RecyclerView.ViewHolder viewHolder, List<Object> payloads)
When an item is changed, ItemAnimator can decide whether it wants to re-use the same ViewHolder for animations or RecyclerView should create a copy of the item and ItemAnimator will use both to run the animation (e.g. cross-fade).
Note that this method will only be called if the RecyclerView.ViewHolder
still has the same
type (getItemViewType(int)
). Otherwise, ItemAnimator will always receive
both RecyclerView.ViewHolder
s in the
animateChange(ViewHolder, ViewHolder, ItemHolderInfo, ItemHolderInfo)
method.
If the payload list is not empty, DefaultItemAnimator returns true
.
When this is the case:
- If you override
animateChange(ViewHolder, ViewHolder, int, int, int, int)
, both ViewHolder arguments will be the same instance. -
If you are not overriding
animateChange(ViewHolder, ViewHolder, int, int, int, int)
, then DefaultItemAnimator will callanimateMove(ViewHolder, int, int, int, int)
and run a move animation instead.
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder : The ViewHolder which represents the changed item's old content. |
payloads |
List : A non-null list of merged payloads that were sent with change
notifications. Can be empty if the adapter is invalidated via
notifyDataSetChanged() . The same list of
payloads will be passed into
onBindViewHolder(ViewHolder, int, List)
method if this method returns true . |
Returns | |
---|---|
boolean |
True if RecyclerView should just rebind to the same ViewHolder or false if
RecyclerView should create a new ViewHolder and pass this ViewHolder to the
ItemAnimator to animate. Default implementation calls
canReuseUpdatedViewHolder(ViewHolder) . |
endAnimation
void endAnimation (RecyclerView.ViewHolder item)
Method called when an animation on a view should be ended immediately.
This could happen when other events, like scrolling, occur, so that
animating views can be quickly put into their proper end locations.
Implementations should ensure that any animations running on the item
are canceled and affected properties are set to their end values.
Also, dispatchAnimationFinished(ViewHolder)
should be called for each finished
animation since the animations are effectively done when this method is called.
Parameters | |
---|---|
item |
RecyclerView.ViewHolder : The item for which an animation should be stopped.
|
endAnimations
void endAnimations ()
Method called when all item animations should be ended immediately.
This could happen when other events, like scrolling, occur, so that
animating views can be quickly put into their proper end locations.
Implementations should ensure that any animations running on any items
are canceled and affected properties are set to their end values.
Also, dispatchAnimationFinished(ViewHolder)
should be called for each finished
animation since the animations are effectively done when this method is called.
isRunning
boolean isRunning ()
Method which returns whether there are any item animations currently running. This method can be used to determine whether to delay other actions until animations end.
Returns | |
---|---|
boolean |
true if there are any item animations currently running, false otherwise. |
runPendingAnimations
void runPendingAnimations ()
Called when there are pending animations waiting to be started. This state
is governed by the return values from
animateAppearance()
,
animateChange()
animatePersistence()
, and
animateDisappearance()
, which inform the RecyclerView that the ItemAnimator wants to be
called later to start the associated animations. runPendingAnimations() will be scheduled
to be run on the next frame.
Annotations
Interfaces
- ActionMenuView.OnMenuItemClickListener
- PopupMenu.OnDismissListener
- PopupMenu.OnMenuItemClickListener
- RecyclerView.ChildDrawingOrderCallback
- RecyclerView.ItemAnimator.ItemAnimatorFinishedListener
- RecyclerView.LayoutManager.LayoutPrefetchRegistry
- RecyclerView.OnChildAttachStateChangeListener
- RecyclerView.OnItemTouchListener
- RecyclerView.RecyclerListener
- RecyclerView.SmoothScroller.ScrollVectorProvider
- SearchView.OnCloseListener
- SearchView.OnQueryTextListener
- SearchView.OnSuggestionListener
- ShareActionProvider.OnShareTargetSelectedListener
- ThemedSpinnerAdapter
- Toolbar.OnMenuItemClickListener
Classes
- ActionMenuView
- ActionMenuView.LayoutParams
- AppCompatAutoCompleteTextView
- AppCompatButton
- AppCompatCheckBox
- AppCompatCheckedTextView
- AppCompatEditText
- AppCompatImageButton
- AppCompatImageView
- AppCompatMultiAutoCompleteTextView
- AppCompatRadioButton
- AppCompatRatingBar
- AppCompatSeekBar
- AppCompatSpinner
- AppCompatTextView
- CardView
- DefaultItemAnimator
- DividerItemDecoration
- GridLayout
- GridLayout.Alignment
- GridLayout.LayoutParams
- GridLayout.Spec
- GridLayoutManager
- GridLayoutManager.DefaultSpanSizeLookup
- GridLayoutManager.LayoutParams
- GridLayoutManager.SpanSizeLookup
- LinearLayoutCompat
- LinearLayoutCompat.LayoutParams
- LinearLayoutManager
- LinearLayoutManager.LayoutChunkResult
- LinearSmoothScroller
- LinearSnapHelper
- ListPopupWindow
- OrientationHelper
- PagerSnapHelper
- PopupMenu
- RecyclerView
- RecyclerView.Adapter
- RecyclerView.AdapterDataObserver
- RecyclerView.EdgeEffectFactory
- RecyclerView.ItemAnimator
- RecyclerView.ItemAnimator.ItemHolderInfo
- RecyclerView.ItemDecoration
- RecyclerView.LayoutManager
- RecyclerView.LayoutManager.Properties
- RecyclerView.LayoutParams
- RecyclerView.OnFlingListener
- RecyclerView.OnScrollListener
- RecyclerView.RecycledViewPool
- RecyclerView.Recycler
- RecyclerView.SimpleOnItemTouchListener
- RecyclerView.SmoothScroller
- RecyclerView.SmoothScroller.Action
- RecyclerView.State
- RecyclerView.ViewCacheExtension
- RecyclerView.ViewHolder
- RecyclerViewAccessibilityDelegate
- RecyclerViewAccessibilityDelegate.ItemDelegate
- SearchView
- ShareActionProvider
- SimpleItemAnimator
- SnapHelper
- StaggeredGridLayoutManager
- StaggeredGridLayoutManager.LayoutParams
- SwitchCompat
- ThemedSpinnerAdapter.Helper
- Toolbar
- Toolbar.LayoutParams
- Toolbar.SavedState
- TooltipCompat