RecyclerView.ItemAnimator

public static abstract class RecyclerView.ItemAnimator
extends Object

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.ItemAnimator


This class defines the animations that take place on items as changes are made to the adapter. Subclasses of ItemAnimator can be used to implement custom animations for actions on ViewHolder items. The RecyclerView will manage retaining these items while they are being animated, but implementors must call dispatchAnimationFinished(ViewHolder) when a ViewHolder's animation is finished. In other words, there must be a matching dispatchAnimationFinished(ViewHolder) call for each animateAppearance(), animateChange() animatePersistence(), and animateDisappearance() call.

By default, RecyclerView uses DefaultItemAnimator.

Summary

Nested classes

@interface RecyclerView.ItemAnimator.AdapterChanges

The set of flags that might be passed to RecyclerView.ItemAnimator.recordPreLayoutInformation(State, ViewHolder, int, List)

interface RecyclerView.ItemAnimator.ItemAnimatorFinishedListener

This interface is used to inform listeners when all pending or running animations in an ItemAnimator are finished. 

class RecyclerView.ItemAnimator.ItemHolderInfo

A simple data structure that holds information about an item's bounds. 

Constants

int FLAG_APPEARED_IN_PRE_LAYOUT

This ViewHolder was not laid out but has been added to the layout in pre-layout state by the RecyclerView.LayoutManager.

int FLAG_CHANGED

The Item represented by this ViewHolder is updated.

int FLAG_INVALIDATED

Adapter RecyclerView.Adapter.notifyDataSetChanged() has been called and the content represented by this ViewHolder is invalid.

int FLAG_MOVED

The position of the Item represented by this ViewHolder has been changed.

int FLAG_REMOVED

The Item represented by this ViewHolder is removed from the adapter.

Public constructors

ItemAnimator()

Public methods

abstract boolean animateAppearance(RecyclerView.ViewHolder viewHolder, RecyclerView.ItemAnimator.ItemHolderInfo preLayoutInfo, RecyclerView.ItemAnimator.ItemHolderInfo postLayoutInfo)

Called by the RecyclerView when a ViewHolder is added to the layout.

abstract boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, RecyclerView.ItemAnimator.ItemHolderInfo preLayoutInfo, RecyclerView.ItemAnimator.ItemHolderInfo postLayoutInfo)

Called by the RecyclerView when an adapter item is present both before and after the layout and RecyclerView has received a RecyclerView.Adapter.notifyItemChanged(int) call for it.

abstract boolean animateDisappearance(RecyclerView.ViewHolder viewHolder, RecyclerView.ItemAnimator.ItemHolderInfo preLayoutInfo, RecyclerView.ItemAnimator.ItemHolderInfo postLayoutInfo)

Called by the RecyclerView when a ViewHolder has disappeared from the layout.

abstract boolean animatePersistence(RecyclerView.ViewHolder viewHolder, RecyclerView.ItemAnimator.ItemHolderInfo preLayoutInfo, RecyclerView.ItemAnimator.ItemHolderInfo postLayoutInfo)

Called by the RecyclerView when a ViewHolder is present in both before and after the layout and RecyclerView has not received a RecyclerView.Adapter.notifyItemChanged(int) call for it or a RecyclerView.Adapter.notifyDataSetChanged() call.

boolean canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder)

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.

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.

final void dispatchAnimationFinished(RecyclerView.ViewHolder viewHolder)

Method to be called by subclasses when an animation is finished.