Skip to content

5.x | Adapter Animations

Davide Steduto edited this page Dec 16, 2017 · 21 revisions

In this page


Scroll animations

Scroll animation is created in the method scrollAnimators() of FlexibleViewHolder.
The method scrollAnimators() is always called by the Adapter if animations have been activated. 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.

Scroll Animations

Activation and 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.
setAnimationEntryStep() 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.

ℹ️ Tip: AnimatorHelper simplifies the creation of basic animations, such as: Alpha, Scale, Flip, 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 available in UI Extension library.

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.

🍒 Tip: AnimatorSubItem class (from the demoApp) has specific animation implemented that you can take as working example.

Suppose you want different and unique add/remove animation on subItems when they are collapsed or expanded. Normally, those animation are performed on all items if an ItemAnimator (for instance LandingAnimator) is assigned to the RecyclerView. Now, 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.

Clone this wiki locally