-
public class DefaultItemAnimator extends SimpleItemAnimator
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.
-
-
Method Summary
Modifier and Type Method Description void
runPendingAnimations()
Called when there are pending animations waiting to be started. boolean
animateRemove(RecyclerView.ViewHolder holder)
Called when an item is removed from the RecyclerView. boolean
animateAdd(RecyclerView.ViewHolder holder)
Called when an item is added to the RecyclerView. boolean
animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY)
Called when an item is moved in 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 notifyItemChanged or notifyItemRangeChanged. 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 thatanimating views can be quickly put into their proper end locations.Implementations should ensure that any animations running on the itemare canceled and affected properties are set to their end values. 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 untilanimations end. void
endAnimations()
Method called when all item animations should be ended immediately.This could happen when other events, like scrolling, occur, so thatanimating views can be quickly put into their proper end locations.Implementations should ensure that any animations running on any itemsare canceled and affected properties are set to their end values. boolean
canReuseUpdatedViewHolder(@NonNull() RecyclerView.ViewHolder viewHolder, @NonNull() List<Object> payloads)
When an item is changed, ItemAnimator can decide whether it wants to re-usethe same ViewHolder for animations or RecyclerView should create a copy of theitem and ItemAnimator will use both to run the animation (e.g. -
Methods inherited from class tds.androidx.recyclerview.widget.SimpleItemAnimator
animateAdd, animateAppearance, animateChange, animateChange, animateDisappearance, animateMove, animatePersistence, animateRemove, canReuseUpdatedViewHolder, dispatchAddFinished, dispatchAddStarting, dispatchChangeFinished, dispatchChangeStarting, dispatchMoveFinished, dispatchMoveStarting, dispatchRemoveFinished, dispatchRemoveStarting, getSupportsChangeAnimations, onAddFinished, onAddStarting, onChangeFinished, onChangeStarting, onMoveFinished, onMoveStarting, onRemoveFinished, onRemoveStarting, setSupportsChangeAnimations
-
Methods inherited from class tds.androidx.recyclerview.widget.RecyclerView.ItemAnimator
animateAppearance, animateChange, animateDisappearance, animatePersistence, canReuseUpdatedViewHolder, canReuseUpdatedViewHolder, dispatchAnimationFinished, dispatchAnimationStarted, dispatchAnimationsFinished, endAnimation, getAddDuration, getChangeDuration, getMoveDuration, getRemoveDuration, isRunning, obtainHolderInfo, onAnimationFinished, onAnimationStarted, recordPostLayoutInformation, recordPreLayoutInformation, setAddDuration, setChangeDuration, setMoveDuration, setRemoveDuration
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
runPendingAnimations
void runPendingAnimations()
Called when there are pending animations waiting to be started. This stateis governed by the return values from animateAppearance(), animateChange() animatePersistence(), and animateDisappearance(), which inform the RecyclerView that the ItemAnimator wants to becalled later to start the associated animations. runPendingAnimations() will be scheduledto be run on the next frame.
-
animateRemove
boolean animateRemove(RecyclerView.ViewHolder holder)
Called when an item is removed from the RecyclerView. Implementors can choosewhether and how to animate that change, but must always call dispatchRemoveFinished when done, eitherimmediately (if no animation will occur) or after the animation actually finishes.The return value indicates whether an animation has been set up and whether theItemAnimator's runPendingAnimations method should be called at thenext opportunity. This mechanism allows ItemAnimator to set up individual animationsas separate calls to animateAdd(), animateMove(), animateRemove(), and animateChange 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 theRecyclerView, but for which the system does not have enough information to animatethem out of view. In that case, the default animation for removing items is runon those items as well.
- Parameters:
holder
- The item that is being removed.
-
animateAdd
boolean animateAdd(RecyclerView.ViewHolder holder)
Called when an item is added to the RecyclerView. Implementors can choosewhether and how to animate that change, but must always call dispatchAddFinished when done, eitherimmediately (if no animation will occur) or after the animation actually finishes.The return value indicates whether an animation has been set up and whether theItemAnimator's runPendingAnimations method should be called at thenext opportunity. This mechanism allows ItemAnimator to set up individual animationsas separate calls to animateAdd(), animateMove(), animateRemove(), and animateChange 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 theRecyclerView, but for which the system does not have enough information to animatethem into view. In that case, the default animation for adding items is runon those items as well.
- Parameters:
holder
- The item that is being added.
-
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 choosewhether and how to animate that change, but must always call dispatchMoveFinished when done, eitherimmediately (if no animation will occur) or after the animation actually finishes.The return value indicates whether an animation has been set up and whether theItemAnimator's runPendingAnimations method should be called at thenext opportunity. This mechanism allows ItemAnimator to set up individual animationsas separate calls to animateAdd(), animateMove(), animateRemove(), and animateChange come in one by one,then start the animations together in the later call to runPendingAnimations.
- Parameters:
holder
- The item that is being moved.
-
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 or notifyItemRangeChanged.
Implementers can choose whether and how to animate changes, but must always call dispatchChangeFinished for each non-null distinct ViewHolder,either immediately (if no animation will occur) or after the animation actually finishes.If the
{@code oldHolder}
is the same ViewHolder as the{@code newHolder}
, you must call dispatchChangeFinished once and only once. In that case, thesecond parameter of{@code dispatchChangeFinished}
is ignored.The return value indicates whether an animation has been set up and whether theItemAnimator's runPendingAnimations method should be called at thenext opportunity. This mechanism allows ItemAnimator to set up individual animationsas separate calls to animateAdd(), animateMove(), animateRemove(), and animateChange come in one by one,then start the animations together in the later call to runPendingAnimations.
- Parameters:
oldHolder
- The original item that changed.newHolder
- The new item that was created with the changed content.
-
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 thatanimating views can be quickly put into their proper end locations.Implementations should ensure that any animations running on the itemare canceled and affected properties are set to their end values.Also, dispatchAnimationFinished should be called for each finishedanimation since the animations are effectively done when this method is called.
- Parameters:
item
- The item for which an animation should be stopped.
-
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 untilanimations end.
-
endAnimations
void endAnimations()
Method called when all item animations should be ended immediately.This could happen when other events, like scrolling, occur, so thatanimating views can be quickly put into their proper end locations.Implementations should ensure that any animations running on any itemsare canceled and affected properties are set to their end values.Also, dispatchAnimationFinished should be called for each finishedanimation since the animations are effectively done when this method is called.
-
canReuseUpdatedViewHolder
boolean canReuseUpdatedViewHolder(@NonNull() RecyclerView.ViewHolder viewHolder, @NonNull() List<Object> payloads)
When an item is changed, ItemAnimator can decide whether it wants to re-usethe same ViewHolder for animations or RecyclerView should create a copy of theitem and ItemAnimator will use both to run the animation (e.g. cross-fade).
Note that this method will only be called if the still has the sametype ( Adapter#getItemViewType(int)). Otherwise, ItemAnimator will always receiveboth 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, bothViewHolder arguments will be the same instance.
- If you are not overriding animateChange,then DefaultItemAnimator will call animateMove andrun a move animation instead.
-
-
-
-