Google is committed to advancing racial equity for Black communities. See how.

ItemAnimator

abstract class ItemAnimator
kotlin.Any
   ↳ 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

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

abstract

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

open

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

Constants
static Int

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

static Int

The Item represented by this ViewHolder is updated.

static Int

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

static Int

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

static Int

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

Public constructors

This class defines the animations that take place on items as changes are made to the adapter.

Public methods
abstract Boolean
animateAppearance(@NonNull viewHolder: RecyclerView.ViewHolder, @Nullable preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo?, @NonNull postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo)

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

abstract Boolean
animateChange(@NonNull oldHolder: RecyclerView.ViewHolder, @NonNull newHolder: RecyclerView.ViewHolder, @NonNull preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @NonNull postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo)

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

abstract Boolean

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

abstract Boolean

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

open Boolean

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

open Boolean
canReuseUpdatedViewHolder(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull payloads: MutableList<Any!>)

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

Unit

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

Unit

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

Unit

This method should be called by ItemAnimator implementations to notify any listeners that all pending and active item animations are finished.

abstract Unit

Method called when an animation on a view should be ended immediately.

abstract Unit

Method called when all item animations should be ended immediately.

open Long

Gets the current duration for which all add animations will run.

open Long

Gets the current duration for which all change animations will run.

open Long

Gets the current duration for which all move animations will run.

open Long

Gets the current duration for which all remove animations will run.

abstract Boolean

Method which returns whether there are any item animations currently running.

Boolean

Like isRunning(), this method returns whether there are any item animations currently running.

open RecyclerView.ItemAnimator.ItemHolderInfo

Returns a new ItemHolderInfo which will be used to store information about the ViewHolder.

open Unit

Called after dispatchAnimationFinished(ViewHolder) is called by the ItemAnimator.

open Unit

Called when a new animation is started on the given ViewHolder.

open RecyclerView.ItemAnimator.ItemHolderInfo

Called by the RecyclerView after the layout is complete.

open RecyclerView.ItemAnimator.ItemHolderInfo
recordPreLayoutInformation(@NonNull state: RecyclerView.State, @NonNull viewHolder: RecyclerView.ViewHolder, changeFlags: Int, @NonNull payloads: MutableList<Any!>)

Called by the RecyclerView before the layout begins.

abstract Unit

Called when there are pending animations waiting to be started.

open Unit
setAddDuration(addDuration: Long)

Sets the duration for which all add animations will run.

open Unit
setChangeDuration(changeDuration: Long)

Sets the duration for which all change animations will run.

open Unit
setMoveDuration(moveDuration: Long)

Sets the duration for which all move animations will run.

open Unit
setRemoveDuration(removeDuration: Long)

Sets the duration for which all remove animations will run.

Constants

FLAG_APPEARED_IN_PRE_LAYOUT

static val FLAG_APPEARED_IN_PRE_LAYOUT: Int

This ViewHolder was not laid out but has been added to the layout in pre-layout state by the LayoutManager. This means that the item was already in the Adapter but invisib