DefaultItemAnimator

This package is part of the
Android support library which
is no longer maintained.
The support library has been superseded by AndroidX
which is part of Jetpack.
We recommend using the AndroidX libraries in all new projects. You should also consider
migrating existing projects to AndroidX.

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.

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.

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.

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.

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.

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.

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.

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.

canReuseUpdatedViewHolder

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).

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

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

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.

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.