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 |
|
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 |
static Int |
The Item represented by this ViewHolder is updated. |
static Int |
Adapter |
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 |
|
---|---|
<init>() 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 |
abstract Boolean |
animateDisappearance(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @Nullable postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo?) Called by the RecyclerView when a ViewHolder has disappeared from the layout. |
abstract Boolean |
animatePersistence(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @NonNull postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo) Called by the RecyclerView when a ViewHolder is present in both before and after the layout and RecyclerView has not received a |
open Boolean |
canReuseUpdatedViewHolder(@NonNull viewHolder: RecyclerView.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. 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 |
dispatchAnimationFinished(@NonNull viewHolder: RecyclerView.ViewHolder) Method to be called by subclasses when an animation is finished. |
Unit |
dispatchAnimationStarted(@NonNull viewHolder: RecyclerView.ViewHolder) 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 |
endAnimation(@NonNull item: RecyclerView.ViewHolder) 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 |
isRunning(@Nullable listener: RecyclerView.ItemAnimator.ItemAnimatorFinishedListener?) Like |
open RecyclerView.ItemAnimator.ItemHolderInfo |
Returns a new |
open Unit |
onAnimationFinished(@NonNull viewHolder: RecyclerView.ViewHolder) Called after |
open Unit |
onAnimationStarted(@NonNull viewHolder: RecyclerView.ViewHolder) Called when a new animation is started on the given ViewHolder. |
open RecyclerView.ItemAnimator.ItemHolderInfo |
recordPostLayoutInformation(@NonNull state: RecyclerView.State, @NonNull viewHolder: RecyclerView.ViewHolder) 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 invisible and it may become visible in the post layout phase. LayoutManagers may prefer to add new items in pre-layout to specify their virtual location when they are invisible (e.g. to specify the item should animate in from below the visible area).
Value: ViewHolder.FLAG_APPEARED_IN_PRE_LAYOUT
FLAG_CHANGED
static val FLAG_CHANGED: Int
The Item represented by this ViewHolder is updated.
Value: ViewHolder.FLAG_UPDATE
FLAG_INVALIDATED
static val FLAG_INVALIDATED: Int
Adapter Adapter#notifyDataSetChanged()
has been called and the content represented by this ViewHolder is invalid.
Value: ViewHolder.FLAG_INVALID
FLAG_MOVED
static val FLAG_MOVED: Int
The position of the Item represented by this ViewHolder has been changed. This flag is not bound to Adapter#notifyItemMoved(int, int)
. It might be set in response to any adapter change that may have a side effect on this item. (e.g. The item before this one has been removed from the Adapter).
Value: ViewHolder.FLAG_MOVED
FLAG_REMOVED
static val FLAG_REMOVED: Int
The Item represented by this ViewHolder is removed from the adapter.
Value: ViewHolder.FLAG_REMOVED
Public constructors
<init>
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
.
See Also
Public methods
animateAppearance
abstract fun animateAppearance(@NonNull viewHolder: RecyclerView.ViewHolder, @Nullable preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo?, @NonNull postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo): Boolean
Called by the RecyclerView when a ViewHolder is added to the layout.
In detail, this means that the ViewHolder was not a child when the layout started but has been added by the LayoutManager. It might be newly added to the adapter or simply become visible due to other factors.
ItemAnimator must call dispatchAnimationFinished(ViewHolder)
when the animation is complete (or instantly call dispatchAnimationFinished(ViewHolder)
if it decides not to animate the view).
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder which should be animated |
preLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from recordPreLayoutInformation(State, ViewHolder, int, List) . Might be null if Item was just added to the adapter or LayoutManager does not support predictive animations or it could not predict that this ViewHolder will become visible. |
postLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from . |
Return | |
---|---|
Boolean: true if a later call to runPendingAnimations() is requested, false otherwise. |
animateChange
abstract fun animateChange(@NonNull oldHolder: RecyclerView.ViewHolder, @NonNull newHolder: RecyclerView.ViewHolder, @NonNull preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @NonNull postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo): Boolean
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. This method may also be called when Adapter#notifyDataSetChanged()
is called and adapter has stable ids so that RecyclerView could still rebind views to the same ViewHolders. If viewType changes when Adapter#notifyDataSetChanged()
is called, this method will not be called, instead, animateAppearance(ViewHolder, ItemHolderInfo, ItemHolderInfo)
will be called for the new ViewHolder and the old one will be recycled.
If this method is called due to a Adapter#notifyDataSetChanged()
call, there is a good possibility that item contents didn't really change but it is rebound from the adapter. DefaultItemAnimator
will skip animating the View if its location on the screen didn't change and your animator should handle this case as well and avoid creating unnecessary animations.
When an item is updated, ItemAnimator has a chance to ask RecyclerView to keep the previous presentation of the item as-is and supply a new ViewHolder for the updated presentation (see: canReuseUpdatedViewHolder(ViewHolder, List)
. This is useful if you don't know the contents of the Item and would like to cross-fade the old and the new one (DefaultItemAnimator
uses this technique).
When you are writing a custom item animator for your layout, it might be more performant and elegant to re-use the same ViewHolder and animate the content changes manually.
When Adapter#notifyItemChanged(int)
is called, the Item's view type may change. If the Item's view type has changed or ItemAnimator returned false
for this ViewHolder when canReuseUpdatedViewHolder(ViewHolder, List)
was called, the oldHolder
and newHolder
will be different ViewHolder instances which represent the same Item. In that case, only the new ViewHolder is visible to the LayoutManager but RecyclerView keeps old ViewHolder attached for animations.
ItemAnimator must call dispatchAnimationFinished(ViewHolder)
for each distinct ViewHolder when their animation is complete (or instantly call dispatchAnimationFinished(ViewHolder)
if it decides not to animate the view).
If oldHolder and newHolder are the same instance, you should call dispatchAnimationFinished(ViewHolder)
only once.
Note that when a ViewHolder both changes and disappears in the same layout pass, the animation callback method which will be called by the RecyclerView depends on the ItemAnimator's decision whether to re-use the same ViewHolder or not, and also the LayoutManager's decision whether to layout the changed version of a disappearing ViewHolder or not. RecyclerView will call animateChange
instead of animateDisappearance
if and only if the ItemAnimator returns false
from canReuseUpdatedViewHolder
and the LayoutManager lays out a new disappearing view that holds the updated information. Built-in LayoutManagers try to avoid laying out updated versions of disappearing views.
Parameters | |
---|---|
oldHolder |
RecyclerView.ViewHolder: The ViewHolder before the layout is started, might be the same instance with newHolder. |
newHolder |
RecyclerView.ViewHolder: The ViewHolder after the layout is finished, might be the same instance with oldHolder. |
preLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from recordPreLayoutInformation(State, ViewHolder, int, List) . |
postLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from . |
Return | |
---|---|
Boolean: true if a later call to runPendingAnimations() is requested, false otherwise. |
animateDisappearance
abstract fun animateDisappearance(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @Nullable postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo?): Boolean
Called by the RecyclerView when a ViewHolder has disappeared from the layout.
This means that the View was a child of the LayoutManager when layout started but has been removed by the LayoutManager. It might have been removed from the adapter or simply become invisible due to other factors. You can distinguish these two cases by checking the change flags that were passed to recordPreLayoutInformation(State, ViewHolder, int, List)
.
Note that when a ViewHolder both changes and disappears in the same layout pass, the animation callback method which will be called by the RecyclerView depends on the ItemAnimator's decision whether to re-use the same ViewHolder or not, and also the LayoutManager's decision whether to layout the changed version of a disappearing ViewHolder or not. RecyclerView will call animateChange
instead of animateDisappearance
if and only if the ItemAnimator returns false
from canReuseUpdatedViewHolder
and the LayoutManager lays out a new disappearing view that holds the updated information. Built-in LayoutManagers try to avoid laying out updated versions of disappearing views.
If LayoutManager supports predictive animations, it might provide a target disappear location for the View by laying it out in that location. When that happens, RecyclerView will call recordPostLayoutInformation(State, ViewHolder)
and the response of that call will be passed to this method as the postLayoutInfo
.
ItemAnimator must call dispatchAnimationFinished(ViewHolder)
when the animation is complete (or instantly call dispatchAnimationFinished(ViewHolder)
if it decides not to animate the view).
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder which should be animated |
preLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from recordPreLayoutInformation(State, ViewHolder, int, List) . |
postLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from recordPostLayoutInformation(State, ViewHolder) . Might be null if the LayoutManager did not layout the item. |
Return | |
---|---|
Boolean: true if a later call to runPendingAnimations() is requested, false otherwise. |
animatePersistence
abstract fun animatePersistence(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull preLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo, @NonNull postLayoutInfo: RecyclerView.ItemAnimator.ItemHolderInfo): 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.
This ViewHolder still represents the same data that it was representing when the layout started but its position / size may be changed by the LayoutManager.
If the Item's layout position didn't change, RecyclerView still calls this method because it does not track this information (or does not necessarily know that an animation is not required). Your ItemAnimator should handle this case and if there is nothing to animate, it should call dispatchAnimationFinished(ViewHolder)
and return false
.
ItemAnimator must call dispatchAnimationFinished(ViewHolder)
when the animation is complete (or instantly call dispatchAnimationFinished(ViewHolder)
if it decides not to animate the view).
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder which should be animated |
preLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from recordPreLayoutInformation(State, ViewHolder, int, List) . |
postLayoutInfo |
RecyclerView.ViewHolder: The information that was returned from . |
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 ViewHolder
s 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 RecyclerView should just rebind to the same ViewHolder or false if RecyclerView should create a new ViewHolder and pass this ViewHolder to the ItemAnimator to animate. Default implementation returns true . |
canReuseUpdatedViewHolder
open fun canReuseUpdatedViewHolder(@NonNull viewHolder: RecyclerView.ViewHolder, @NonNull payloads: MutableList<Any!>): 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 ViewHolder
s in the animateChange(ViewHolder, ViewHolder, ItemHolderInfo, ItemHolderInfo)
method.
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder which represents the changed item's old content. |
payloads |
RecyclerView.ViewHolder: A non-null list of merged payloads that were sent with change notifications. Can be empty if the adapter is invalidated via RecyclerView.Adapter#notifyDataSetChanged() . The same list of payloads will be passed into RecyclerView.Adapter#onBindViewHolder(ViewHolder, int, List) method if this method returns true . |
Return | |
---|---|
Boolean: True if RecyclerView should just rebind to the same ViewHolder or false if RecyclerView should create a new ViewHolder and pass this ViewHolder to the ItemAnimator to animate. Default implementation calls canReuseUpdatedViewHolder(ViewHolder) . |
dispatchAnimationFinished
fun dispatchAnimationFinished(@NonNull viewHolder: RecyclerView.ViewHolder): Unit
Method to be called by subclasses when an animation is finished.
For each call RecyclerView makes to animateAppearance()
, animatePersistence()
, or animateDisappearance()
, there should be a matching dispatchAnimationFinished(ViewHolder)
call by the subclass.
For animateChange()
, subclass should call this method for both the oldHolder
and newHolder
(if they are not the same instance).
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder whose animation is finished. |
See Also
dispatchAnimationStarted
fun dispatchAnimationStarted(@NonNull viewHolder: RecyclerView.ViewHolder): Unit
Method to be called by subclasses when an animation is started.
For each call RecyclerView makes to animateAppearance()
, animatePersistence()
, or animateDisappearance()
, there should be a matching dispatchAnimationStarted(ViewHolder)
call by the subclass.
For animateChange()
, subclass should call this method for both the oldHolder
and newHolder
(if they are not the same instance).
If your ItemAnimator decides not to animate a ViewHolder, it should call dispatchAnimationFinished(ViewHolder)
without calling dispatchAnimationStarted(ViewHolder)
.
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder whose animation is starting. |
See Also
dispatchAnimationsFinished
fun dispatchAnimationsFinished(): Unit
This method should be called by ItemAnimator implementations to notify any listeners that all pending and active item animations are finished.
endAnimation
abstract fun endAnimation(@NonNull item: RecyclerView.ViewHolder): Unit
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, dispatchAnimationFinished(ViewHolder)
should be called for each finished animation since the animations are effectively done when this method is called.
Parameters | |
---|---|
item |
RecyclerView.ViewHolder: The item for which an animation should be stopped. |
endAnimations
abstract fun endAnimations(): Unit
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, dispatchAnimationFinished(ViewHolder)
should be called for each finished animation since the animations are effectively done when this method is called.
getAddDuration
open fun getAddDuration(): Long
Gets the current duration for which all add animations will run.
Return | |
---|---|
Long: The current add duration |
getChangeDuration
open fun getChangeDuration(): Long
Gets the current duration for which all change animations will run.
Return | |
---|---|
Long: The current change duration |
getMoveDuration
open fun getMoveDuration(): Long
Gets the current duration for which all move animations will run.
Return | |
---|---|
Long: The current move duration |
getRemoveDuration
open fun getRemoveDuration(): Long
Gets the current duration for which all remove animations will run.
Return | |
---|---|
Long: The current remove duration |
isRunning
abstract fun isRunning(): Boolean
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.
Return | |
---|---|
Boolean: true if there are any item animations currently running, false otherwise. |
isRunning
fun isRunning(@Nullable listener: RecyclerView.ItemAnimator.ItemAnimatorFinishedListener?): Boolean
Like isRunning()
, this method returns whether there are any item animations currently running. Additionally, the listener passed in will be called when there are no item animations running, either immediately (before the method returns) if no animations are currently running, or when the currently running animations are finished
.
Note that the listener is transient - it is either called immediately and not stored at all, or stored only until it is called when running animations are finished sometime later.
Parameters | |
---|---|
listener |
RecyclerView.ItemAnimator.ItemAnimatorFinishedListener?: A listener to be called immediately if no animations are running or later when currently-running animations have finished. A null listener is equivalent to calling isRunning() . |
Return | |
---|---|
Boolean: true if there are any item animations currently running, false otherwise. |
obtainHolderInfo
@NonNull open fun obtainHolderInfo(): RecyclerView.ItemAnimator.ItemHolderInfo
Returns a new ItemHolderInfo
which will be used to store information about the ViewHolder. This information will later be passed into animate**
methods.
You can override this method if you want to extend ItemHolderInfo
and provide your own instances.
Return | |
---|---|
RecyclerView.ItemAnimator.ItemHolderInfo: A new ItemHolderInfo . |
onAnimationFinished
open fun onAnimationFinished(@NonNull viewHolder: RecyclerView.ViewHolder): Unit
Called after dispatchAnimationFinished(ViewHolder)
is called by the ItemAnimator.
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder whose animation is finished. There might still be other animations running on this ViewHolder. |
onAnimationStarted
open fun onAnimationStarted(@NonNull viewHolder: RecyclerView.ViewHolder): Unit
Called when a new animation is started on the given ViewHolder.
Parameters | |
---|---|
viewHolder |
RecyclerView.ViewHolder: The ViewHolder which started animating. Note that the ViewHolder might already be animating and this might be another animation. |
recordPostLayoutInformation
@NonNull open fun recordPostLayoutInformation(@NonNull state: RecyclerView.State, @NonNull viewHolder: RecyclerView.ViewHolder): RecyclerView.ItemAnimator.ItemHolderInfo
Called by the RecyclerView after the layout is complete. Item animator should record necessary information about the View's final state.
The data returned from this method will be passed to the related animate**
methods.
The default implementation returns an ItemHolderInfo
which holds the bounds of the View.
Parameters | |
---|---|
state |
RecyclerView.State: The current State of RecyclerView which includes some useful data about the layout that will be calculated. |
viewHolder |
RecyclerView.State: The ViewHolder whose information should be recorded. |
Return | |
---|---|
RecyclerView.ItemAnimator.ItemHolderInfo: An ItemHolderInfo that preserves necessary information about the ViewHolder. This object will be passed back to related animate** methods when RecyclerView decides how items should be animated. |
See Also
#recordPreLayoutInformation(State, ViewHolder, int, List)#animateAppearance(ViewHolder, ItemHolderInfo, ItemHolderInfo)#animateDisappearance(ViewHolder, ItemHolderInfo, ItemHolderInfo)#animateChange(ViewHolder, ViewHolder, ItemHolderInfo, ItemHolderInfo)#animatePersistence(ViewHolder, ItemHolderInfo, ItemHolderInfo)
recordPreLayoutInformation
@NonNull open fun recordPreLayoutInformation(@NonNull state: RecyclerView.State, @NonNull viewHolder: RecyclerView.ViewHolder, changeFlags: Int, @NonNull payloads: MutableList<Any!>): RecyclerView.ItemAnimator.ItemHolderInfo
Called by the RecyclerView before the layout begins. Item animator should record necessary information about the View before it is potentially rebound, moved or removed.
The data returned from this method will be passed to the related animate**
methods.
Note that this method may be called after pre-layout phase if LayoutManager adds new Views to the layout in pre-layout pass.
The default implementation returns an ItemHolderInfo
which holds the bounds of the View and the adapter change flags.
Parameters | |
---|---|
state |
RecyclerView.State: The current State of RecyclerView which includes some useful data about the layout that will be calculated. |
viewHolder |
RecyclerView.State: The ViewHolder whose information should be recorded. |
changeFlags |
RecyclerView.State: Additional information about what changes happened in the Adapter about the Item represented by this ViewHolder. For instance, if item is deleted from the adapter, FLAG_REMOVED will be set. |
payloads |
RecyclerView.State: The payload list that was previously passed to Adapter#notifyItemChanged(int, Object) or Adapter#notifyItemRangeChanged(int, int, Object) . |
Return | |
---|---|
RecyclerView.ItemAnimator.ItemHolderInfo: An ItemHolderInfo instance that preserves necessary information about the ViewHolder. This object will be passed back to related animate** methods after layout is complete. |
See Also
#recordPostLayoutInformation(State, ViewHolder)#animateAppearance(ViewHolder, ItemHolderInfo, ItemHolderInfo)#animateDisappearance(ViewHolder, ItemHolderInfo, ItemHolderInfo)#animateChange(ViewHolder, ViewHolder, ItemHolderInfo, ItemHolderInfo)#animatePersistence(ViewHolder, ItemHolderInfo, ItemHolderInfo)
runPendingAnimations
abstract fun runPendingAnimations(): Unit
Called when there are pending animations waiting to be started. This state is governed by the return values from animateAppearance()
, animateChange()
animatePersistence()
, and animateDisappearance()
, 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.
setAddDuration
open fun setAddDuration(addDuration: Long): Unit
Sets the duration for which all add animations will run.
Parameters | |
---|---|
addDuration |
Long: The add duration |
setChangeDuration
open fun setChangeDuration(changeDuration: Long): Unit
Sets the duration for which all change animations will run.
Parameters | |
---|---|
changeDuration |
Long: The change duration |
setMoveDuration
open fun setMoveDuration(moveDuration: Long): Unit
Sets the duration for which all move animations will run.
Parameters | |
---|---|
moveDuration |
Long: The move duration |