SimpleItemAnimator

abstract class SimpleItemAnimator : RecyclerView.ItemAnimator
kotlin.Any
   ↳ androidx.recyclerview.widget.RecyclerView.ItemAnimator
   ↳ androidx.recyclerview.widget.SimpleItemAnimator

A wrapper class for ItemAnimator that records View bounds and decides whether it should run move, change, add or remove animations. This class also replicates the original ItemAnimator API.

It uses RecyclerView.ItemAnimator.ItemHolderInfo to track the bounds information of the Views. If you would like to extend this class, you can override obtainHolderInfo() method to provide your own info class that extends RecyclerView.ItemAnimator.ItemHolderInfo.

Summary

Inherited constants

Public constructors

A wrapper class for ItemAnimator that records View bounds and decides whether it should run move, change, add or remove animations.

Public methods

abstract Boolean

Called when an item is added to the RecyclerView.

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

open Boolean

abstract Boolean
animateChange(oldHolder: RecyclerView.ViewHolder!, newHolder: RecyclerView.ViewHolder!, fromLeft: Int, fromTop: Int, toLeft: Int, toTop: Int)

Called when an item is changed in the RecyclerView, as indicated by a call to RecyclerView.Adapter#notifyItemChanged(int) or RecyclerView.Adapter#notifyItemRangeChanged(int, int).

open Boolean

abstract Boolean
animateMove(holder: RecyclerView.ViewHolder!, fromX: Int, fromY: Int, toX: Int, toY: Int)

Called when an item is moved in the RecyclerView.

open Boolean

abstract Boolean

Called when an item is removed from the RecyclerView.

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

Unit

Method to be called by subclasses when an add animation is done.

Unit

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

Unit

Method to be called by subclasses when a change animation is done.

Unit

Method to be called by subclasses when a change animation is being started.

Unit

Method to be called by subclasses when a move animation is done.

Unit

Method to be called by subclasses when a move animation is being started.

Unit

Method to be called by subclasses when a remove animation is done.

Unit

Method to be called by subclasses when a remove animation is being started.

open Boolean

Returns whether this ItemAnimator supports animations of change events.

open Unit

Called when an add animation has ended on the given ViewHolder.

open Unit

Called when an add animation is being started on the given ViewHolder.

open Unit

Called when a change animation has ended on the given ViewHolder.

open Unit

Called when a change animation is being started on the given ViewHolder.

open Unit

Called when a move animation has ended on the given ViewHolder.

open Unit

Called when a move animation is being started on the given ViewHolder.

open Unit

Called when a remove animation has ended on the given ViewHolder.

open Unit

Called when a remove animation is being started on the given ViewHolder.

open Unit
setSupportsChangeAnimations(supportsChangeAnimations: Boolean)

Sets whether this ItemAnimator supports animations of item change events.

Inherited functions

Public constructors

<init>

SimpleItemAnimator()

A wrapper class for ItemAnimator that records View bounds and decides whether it should run move, change, add or remove animations. This class also replicates the original ItemAnimator API.

It uses RecyclerView.ItemAnimator.ItemHolderInfo to track the bounds information of the Views. If you would like to extend this class, you can override obtainHolderInfo() method to provide your own info class that extends RecyclerView.ItemAnimator.ItemHolderInfo.

Public methods

animateAdd

abstract fun animateAdd(holder: RecyclerView.ViewHolder!): Boolean

Called when an item is added to the RecyclerView. Implementors can choose whether and how to animate that change, but must always call dispatchAddFinished(RecyclerView.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(RecyclerView.ViewHolder, RecyclerView.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 RecyclerView.ViewHolder!: The item that is being added.
Return
Boolean: true if a later call to runPendingAnimations() is requested, false otherwise.

animateAppearance

open fun animateAppearance(@NonNull viewHolder: RecyclerView.ViewHolder, @Nullable preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo?, @NonNull postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo): Boolean

animateChange

open fun animateChange(@NonNull oldHolder: RecyclerView.ViewHolder, @NonNull newHolder: RecyclerView.ViewHolder, @NonNull preInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @NonNull postInfo: RecyclerView.ItemAnimator.ItemHolderInfo): Boolean

animateChange

abstract fun animateChange(oldHolder: RecyclerView.ViewHolder!, newHolder: RecyclerView.ViewHolder!, fromLeft: Int, fromTop: Int, toLeft: Int, toTop: Int): Boolean

Called when an item is changed in the RecyclerView, as indicated by a call to RecyclerView.Adapter#notifyItemChanged(int) or RecyclerView.Adapter#notifyItemRangeChanged(int, int).

Implementers can choose whether and how to animate changes, but must always call dispatchChangeFinished(RecyclerView.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(RecyclerView.ViewHolder, boolean) once and only once. In that case, the second parameter of dispatchChangeFinished is ignored.

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(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int) come in one by one, then start the animations together in the later call to runPendingAnimations().

Parameters
oldHolder RecyclerView.ViewHolder!: The original item that changed.
newHolder RecyclerView.ViewHolder!: The new item that was created with the changed content. Might be null
fromLeft RecyclerView.ViewHolder!: Left of the old view holder
fromTop RecyclerView.ViewHolder!: Top of the old view holder
toLeft RecyclerView.ViewHolder!: Left of the new view holder
toTop RecyclerView.ViewHolder!: Top of the new view holder
Return
Boolean: true if a later call to runPendingAnimations() is requested, false otherwise.

animateDisappearance

open fun animateDisappearance(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @Nullable postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo?): Boolean

animateMove

abstract fun animateMove(holder: RecyclerView.ViewHolder!, fromX: Int, fromY: Int, toX: Int, toY: Int): Boolean

Called when an item is moved in the RecyclerView. Implementors can choose whether and how to animate that change, but must always call dispatchMoveFinished(RecyclerView.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(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int) come in one by one, then start the animations together in the later call to runPendingAnimations().

Parameters
holder RecyclerView.ViewHolder!: The item that is being moved.
Return
Boolean: true if a later call to runPendingAnimations() is requested, false otherwise.

animatePersistence

open fun animatePersistence(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull preInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @NonNull postInfo: RecyclerView.ItemAnimator.ItemHolderInfo): Boolean

animateRemove

abstract fun animateRemove(holder: RecyclerView.ViewHolder!): Boolean

Called when an item is removed from the RecyclerView. Implementors can choose whether and how to animate that change, but must always call dispatchRemoveFinished(RecyclerView.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(RecyclerView.ViewHolder, RecyclerView.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 RecyclerView.ViewHolder!: The item that is being removed.
Return
Boolean: true if a later call to runPendingAnimations() is requested, false otherwise.

canReuseUpdatedViewHolder

open fun canReuseUpdatedViewHolder(@NonNull viewHolder: RecyclerView.ViewHolder): 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).

Note that this method will only be called if the ViewHolder still has the same type (Adapter#getItemViewType(int)). Otherwise, ItemAnimator will always receive both ViewHolders in the animateChange(ViewHolder, ViewHolder, ItemHolderInfo, ItemHolderInfo) method.

If your application is using change payloads, you can override canReuseUpdatedViewHolder(ViewHolder, List) to decide based on payloads.

Parameters
viewHolder RecyclerView.ViewHolder: The ViewHolder which represents the changed item's old content.
Return
Boolean: True if change animations are not supported or the ViewHolder is invalid, false otherwise.

dispatchAddFinished

fun dispatchAddFinished(item: RecyclerView.ViewHolder!): Unit

Method to be called by subclasses when an add animation is done.

Parameters
item RecyclerView.ViewHolder!: The item which has been added

dispatchAddStarting

fun dispatchAddStarting(item: RecyclerView.ViewHolder!): Unit

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

Parameters
item RecyclerView.ViewHolder!: The item being added

dispatchChangeFinished

fun dispatchChangeFinished(item: RecyclerView.ViewHolder!, oldItem: Boolean): Unit

Method to be called by subclasses when a change animation is done.

Parameters
item RecyclerView.ViewHolder!: The item which has been changed (this method must be called for each non-null ViewHolder passed into animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)).
oldItem RecyclerView.ViewHolder!: true if this is the old item that was changed, false if it is the new item that replaced the old item.

dispatchChangeStarting

fun dispatchChangeStarting(item: RecyclerView.ViewHolder!, oldItem: Boolean): Unit

Method to be called by subclasses when a change animation is being started.

Parameters
item RecyclerView.ViewHolder!: The item which has been changed (this method must be called for each non-null ViewHolder passed into animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)).
oldItem RecyclerView.ViewHolder!: true if this is the old item that was changed, false if it is the new item that replaced the old item.

dispatchMoveStarting

fun dispatchMoveStarting(item: RecyclerView.ViewHolder!): Unit

Method to be called by subclasses when a move animation is being started.

Parameters
item RecyclerView.ViewHolder!: The item being moved

dispatchRemoveFinished

fun dispatchRemoveFinished(item: RecyclerView.ViewHolder!): Unit

Method to be called by subclasses when a remove animation is done.

Parameters
item RecyclerView.ViewHolder!: The item which has been removed

dispatchRemoveStarting

fun dispatchRemoveStarting(item: RecyclerView.ViewHolder!): Unit

Method to be called by subclasses when a remove animation is being started.

Parameters
item RecyclerView.ViewHolder!: The item being removed

getSupportsChangeAnimations

open fun getSupportsChangeAnimations(): Boolean

Returns whether this ItemAnimator supports animations of change events.

Return
Boolean: true if change animations are supported, false otherwise

onAddFinished

open fun onAddFinished(item: RecyclerView.ViewHolder!): Unit

Called when an add animation has ended on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.

onAddStarting

open fun onAddStarting(item: RecyclerView.ViewHolder!): Unit

Called when an add animation is being started on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.

onChangeFinished

open fun onChangeFinished(item: RecyclerView.ViewHolder!, oldItem: Boolean): Unit

Called when a change animation has ended on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.
oldItem RecyclerView.ViewHolder!: true if this is the old item that was changed, false if it is the new item that replaced the old item.

onChangeStarting

open fun onChangeStarting(item: RecyclerView.ViewHolder!, oldItem: Boolean): Unit

Called when a change animation is being started on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.
oldItem RecyclerView.ViewHolder!: true if this is the old item that was changed, false if it is the new item that replaced the old item.

onMoveFinished

open fun onMoveFinished(item: RecyclerView.ViewHolder!): Unit

Called when a move animation has ended on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.

onMoveStarting

open fun onMoveStarting(item: RecyclerView.ViewHolder!): Unit

Called when a move animation is being started on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.

onRemoveFinished

open fun onRemoveFinished(item: RecyclerView.ViewHolder!): Unit

Called when a remove animation has ended on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.

onRemoveStarting

open fun onRemoveStarting(item: RecyclerView.ViewHolder!): Unit

Called when a remove animation is being started on the given ViewHolder. The default implementation does nothing. Subclasses may wish to override this method to handle any ViewHolder-specific operations linked to animation lifecycles.

Parameters
item RecyclerView.ViewHolder!: The ViewHolder being animated.

setSupportsChangeAnimations

open fun setSupportsChangeAnimations(supportsChangeAnimations: Boolean): Unit

Sets whether this ItemAnimator supports animations of item change events. If you set this property to false, actions on the data set which change the contents of items will not be animated. What those animations do is left up to the discretion of the ItemAnimator subclass, in its animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int) implementation. The value of this property is true by default.

Parameters
supportsChangeAnimations Boolean: true if change animations are supported by this ItemAnimator, false otherwise. If the property is false, the ItemAnimator will not receive a call to animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, * int) when changes occur.