Skip to content

5.x | Adapter Animations

Davide Steduto edited this page Sep 18, 2016 · 21 revisions

In this page

  • Scroll Animators
  • Item Animators (when items are notified)

Scroll Animations

The specific animation is created in the method scrollAnimators() of FlexibleViewHolder. Activation and common configuration is done by calling the following methods of FlexibleAdapter:

Method name Description
setAnimationOnScrolling() Enable/Disable item animation while scrolling and on loading. Enabling scrolling will disable onlyEntryAnimation. Disabling scrolling will disable also reverse scrolling! Default value is false.
setAnimationOnReverseScrolling() Enable reverse scrolling animation if AnimationOnScrolling is also enabled! Value is ignored if basic animation on scrolling is disabled. Default value is false (only forward).
setOnlyEntryAnimation() Performs only entry animation during the initial loading. Stops the animation after the last visible item in the RecyclerView has been animated. Note: Loading animation can only be performed if the Adapter is initialized with some items using the Constructor. Default value is false.
setEntryStepDelay() If initial loading animation should use step delay between an item animation and the next. When false, all items are animated with no delay. Better to disable when using Grid layouts. Default value is true.
setAnimationInitialDelay() Customize the initial delay for the first item animation. Default value is 0ms.
setAnimationDelay() Customize the step delay between an animation and the next to be added to the initial delay. The delay is added on top of the previous delay. Default value is 100ms.
setAnimationDuration() Customize the duration of the animation for ALL items. Default value is 300ms.
setAnimationInterpolator() Define a custom interpolator for ALL items. Default value is LinearInterpolator.
setAnimationStartPosition() Define an initial start animation adapter position. Default value is 0 (1st position).

The method scrollAnimators() is always called by the Adapter if animations have been activated. If you want the view will animate when scrolling, you just need to override it by adding new animators to the list of Animators. Usually animation is applied to itemView but you can apply to any view in the itemView.

Note: AnimatorHelper simplifies the creation of basic animations, such as: Alpha, Scale, SlideInFromLeft, SlideInFromRight, SlideInFromBottom, SlideInFromTop.

Item Animations (when items are notified)

These animations occur when adding/removing/moving/changing notifications are triggered on an item. This library has a custom implementation of SimpleItemAnimator, named FlexibleItemAnimator.

FlexibleItemAnimator class has more options than recyclerview-animators library. It allows to set a delay based on the index of the items to animate and has the possibility to be overridden by the animation implemented in the ViewHolder.

Example: Suppose you want different add/remove animation on subItems when they are collapsed or expanded. Animation are performed on all items if an ItemAnimator (for instance LandingAnimator) is assigned to the RecyclerView. But specific Animation can be performed on the single ViewHolder if the ViewHolder implements AnimatedViewHolder and the methods return true, then the general ItemAnimator is therefore overridden.

To be continued

Clone this wiki locally