Package 

Class RecyclerView.ItemAnimator

    • Method Detail

      • getMoveDuration

         long getMoveDuration()

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

      • setMoveDuration

         void setMoveDuration(long moveDuration)

        Sets the duration for which all move animations will run.

        Parameters:
        moveDuration - The move duration
      • getAddDuration

         long getAddDuration()

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

      • setAddDuration

         void setAddDuration(long addDuration)

        Sets the duration for which all add animations will run.

        Parameters:
        addDuration - The add duration
      • getRemoveDuration

         long getRemoveDuration()

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

      • setRemoveDuration

         void setRemoveDuration(long removeDuration)

        Sets the duration for which all remove animations will run.

        Parameters:
        removeDuration - The remove duration
      • getChangeDuration

         long getChangeDuration()

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

      • setChangeDuration

         void setChangeDuration(long changeDuration)

        Sets the duration for which all change animations will run.

        Parameters:
        changeDuration - The change duration
      • recordPreLayoutInformation

        @NonNull() RecyclerView.ItemAnimator.ItemHolderInfo recordPreLayoutInformation(@NonNull() RecyclerView.State state, @NonNull() RecyclerView.ViewHolder viewHolder, int changeFlags, @NonNull() List<Object> payloads)

        Called by the RecyclerView before the layout begins. Item animator should recordnecessary 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 newViews to the layout in pre-layout pass.

        The default implementation returns an ItemHolderInfo which holds the bounds ofthe View and the adapter change flags.

        Parameters:
        state - The current State of RecyclerView which includes some useful dataabout the layout that will be calculated.
        viewHolder - The ViewHolder whose information should be recorded.
        changeFlags - Additional information about what changes happened in the Adapterabout the Item represented by this ViewHolder.
        payloads - The payload list that was previously passed tonotifyItemChanged ornotifyItemRangeChanged.
      • animateDisappearance

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

        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 hasbeen removed by the LayoutManager. It might have been removed from the adapter or simplybecome invisible due to other factors. You can distinguish these two cases by checkingthe change flags that were passed to recordPreLayoutInformation.

        Note that when a ViewHolder both changes and disappears in the same layout pass, theanimation callback method which will be called by the RecyclerView depends on theItemAnimator's decision whether to re-use the same ViewHolder or not, and also theLayoutManager's decision whether to layout the changed version of a disappearingViewHolder or not. RecyclerView will call animateChange instead of {@code animateDisappearance} if and only if the ItemAnimatorreturns {@code false} from canReuseUpdatedViewHolder and theLayoutManager 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 disappearlocation for the View by laying it out in that location. When that happens,RecyclerView will call recordPostLayoutInformation and theresponse of that call will be passed to this method as the postLayoutInfo.

        ItemAnimator must call dispatchAnimationFinished when the animationis complete (or instantly call dispatchAnimationFinished if itdecides not to animate the view).

        Parameters:
        viewHolder - The ViewHolder which should be animated
        preLayoutInfo - The information that was returned fromrecordPreLayoutInformation.
        postLayoutInfo - The information that was returned fromrecordPostLayoutInformation.
      • animateChange

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

        Called by the RecyclerView when an adapter item is present both before and after thelayout and RecyclerView has received a notifyItemChanged callfor it. This method may also be called when notifyDataSetChanged is called and adapter has stable ids so thatRecyclerView could still rebind views to the same ViewHolders. If viewType changes when notifyDataSetChanged is called, this method will not be called,instead, animateAppearance will becalled for the new ViewHolder and the old one will be recycled.

        If this method is called due to a notifyDataSetChanged call, there isa good possibility that item contents didn't really change but it is rebound from theadapter. DefaultItemAnimator will skip animating the View if its location on thescreen didn't change and your animator should handle this case as well and avoid creatingunnecessary animations.

        When an item is updated, ItemAnimator has a chance to ask RecyclerView to keep theprevious presentation of the item as-is and supply a new ViewHolder for the updatedpresentation (see: canReuseUpdatedViewHolder.This is useful if you don't know the contents of the Item and would liketo 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 performantand elegant to re-use the same ViewHolder and animate the content changes manually.

        When notifyItemChanged is called, the Item's view type may change.If the Item's view type has changed or ItemAnimator returned false forthis ViewHolder when canReuseUpdatedViewHolder was called, theoldHolder and newHolder will be different ViewHolder instanceswhich represent the same Item. In that case, only the new ViewHolder is visibleto the LayoutManager but RecyclerView keeps old ViewHolder attached for animations.

        ItemAnimator must call dispatchAnimationFinished for each distinctViewHolder when their animation is complete(or instantly call dispatchAnimationFinished if it decides not toanimate the view).

        If oldHolder and newHolder are the same instance, you should call dispatchAnimationFinishedonly once.

        Note that when a ViewHolder both changes and disappears in the same layout pass, theanimation callback method which will be called by the RecyclerView depends on theItemAnimator's decision whether to re-use the same ViewHolder or not, and also theLayoutManager's decision whether to layout the changed version of a disappearingViewHolder or not. RecyclerView will call {@code animateChange} instead of animateDisappearance if and only if the ItemAnimator returns {@code false} from canReuseUpdatedViewHolder and theLayoutManager 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 - The ViewHolder before the layout is started, might be the sameinstance with newHolder.
        newHolder - The ViewHolder after the layout is finished, might be the sameinstance with oldHolder.
        preLayoutInfo - The information that was returned fromrecordPreLayoutInformation.
        postLayoutInfo - The information that was returned from .
      • endAnimation

         abstract void endAnimation(@NonNull() 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 thatanimating views can be quickly put into their proper end locations.Implementations should ensure that any animations running on the itemare canceled and affected properties are set to their end values.Also, dispatchAnimationFinished should be called for each finishedanimation since the animations are effectively done when this method is called.

        Parameters:
        item - The item for which an animation should be stopped.
      • endAnimations

         abstract void endAnimations()

        Method called when all item animations should be ended immediately.This could happen when other events, like scrolling, occur, so thatanimating views can be quickly put into their proper end locations.Implementations should ensure that any animations running on any itemsare canceled and affected properties are set to their end values.Also, dispatchAnimationFinished should be called for each finishedanimation since the animations are effectively done when this method is called.

      • isRunning

         abstract 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 untilanimations end.

      • isRunning

         final boolean isRunning(@Nullable() RecyclerView.ItemAnimator.ItemAnimatorFinishedListener listener)

        Like isRunning, this method returns whether there are any itemanimations currently running. Additionally, the listener passed in will be calledwhen there are no item animations running, either immediately (before the methodreturns) if no animations are currently running, or when the currently runninganimations are finished.

        Note that the listener is transient - it is either called immediately and notstored at all, or stored only until it is called when running animationsare finished sometime later.

        Parameters:
        listener - A listener to be called immediately if no animations are runningor later when currently-running animations have finished.
      • canReuseUpdatedViewHolder

         boolean canReuseUpdatedViewHolder(@NonNull() RecyclerView.ViewHolder viewHolder)

        When an item is changed, ItemAnimator can decide whether it wants to re-usethe same ViewHolder for animations or RecyclerView should create a copy of theitem 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 sametype (getItemViewType). Otherwise, ItemAnimator will always receiveboth ViewHolders in the animateChange method.

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

        Parameters:
        viewHolder - The ViewHolder which represents the changed item's old content.
      • canReuseUpdatedViewHolder

         boolean canReuseUpdatedViewHolder(@NonNull() RecyclerView.ViewHolder viewHolder, @NonNull() List<Object> payloads)

        When an item is changed, ItemAnimator can decide whether it wants to re-usethe same ViewHolder for animations or RecyclerView should create a copy of theitem 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 sametype (getItemViewType). Otherwise, ItemAnimator will always receiveboth ViewHolders in the animateChange method.

        Parameters:
        viewHolder - The ViewHolder which represents the changed item's old content.
        payloads - A non-null list of merged payloads that were sent with changenotifications.
      • dispatchAnimationsFinished

         final void dispatchAnimationsFinished()

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