Android APIs
public class

DefaultItemAnimator

extends RecyclerView.ItemAnimator
java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.ItemAnimator
     ↳ android.support.v7.widget.DefaultItemAnimator

Class Overview

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

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 notifyItemChanged(int) or notifyItemRangeChanged(int, int).
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.
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.
[Expand]
Inherited Methods
From class android.support.v7.widget.RecyclerView.ItemAnimator
From class java.lang.Object

Public Constructors

public DefaultItemAnimator ()

Public Methods

public 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 The item that is being added.
Returns

public 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 ViewHolder, 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
oldHolder The original item that changed.
newHolder The new item that was created with the changed content. Might be null
fromX Left of the old view holder
fromY Top of the old view holder
toX Left of the new view holder
toY Top of the new view holder
Returns

public 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 The item that is being moved.
Returns

public 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 The item that is being removed.
Returns

public 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, appropriate dispatch methods (e.g., dispatchAddFinished(ViewHolder) should be called since the animations are effectively done when this method is called.

Parameters
item The item for which an animation should be stopped.

public 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, appropriate dispatch methods (e.g., dispatchAddFinished(ViewHolder) should be called since the animations are effectively done when this method is called.

public 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
  • true if there are any item animations currently running, false otherwise.

public void runPendingAnimations ()

Called when there are pending animations waiting to be started. This state is governed by the return values from animateAdd(), animateMove(), and animateRemove(), 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.