The scrolling in the listview, recycler view, or scroll view has no animation by default and is okay until the length of the scroll is not so big. From then, it gets boring. Here is this amazing android library that will make scrolling as interesting as playing a game.
demo.gif.mp4
- Easy 2 use, builder pattern.
- Supports ListView, RecyclerView and ScrollView
- Supports Fade animation
- Supports Sliding animation
- Supports Rotating animation
- Supports Dropping animation
Add it in your root build.gradle (or gradle.settings) in latest android studio) at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.ErrorxCode:Animify:v1.0'
}
To animate a listview, recycler view, or scroll view
(NestedScrollView too) with default animation properties:
ScrollAnimator.create().animate(view); // view can be list/recycler/scroll View
This will animate the respected view with the default Alpha animation, Fast duration and linear interpolator.
Note: for listviews and recycler views, this must be called after setting the adapter to it.
To customize the animation, set the values using the builder pattern before
calling animate()
Example:
ScrollAnimator.create()
.withAnimation(Animations.ANIMATION_ALPHA)
.withInterpolator(Animations.INTERPOLATOR_OVERSHOOT)
.tillDuration(Animations.DURATION_FAST)
.playOnlyOnDownScroll(true)
.animate(view);
Tip: You can view documentation for each method by hovering the cursor in android studio
You can also pass multiple animations in the withAnimation()
method to merge different animations.
Note: If you are already using onScrollChangeListener()
on your scrollview then, use
animateOnScroll(int,int)
instead of animate(Scrollview)
. Call this method in onScrollChange()
of your
listener.
To use a custom property for animation instead of the library provided one, use withCustom()
method
Example:
ScrollAnimator.create()
.withCustom("backgroundColor", Color.GREEN,Color.BLUE)
... // rest of the methods
.animate(view);
here,
- 'background-color' is the name of the property. It is similar to this method.
- Color.GREEN is the starting value from where to animate.
- Color.BLUE is the ending value till were animate.
This will result in the animation that will animate specified property from starting value to ending value.
listView.setAdapter(adapter);
ScrollAnimator.create()
.withAnimation(Animations.ANIMATION_ALPHA)
.withInterpolator(Animations.INTERPOLATOR_OVERSHOOT)
.tillDuration(Animations.DURATION_FAST)
.playOnlyOnDownScroll(true)
.animate(litview);
NestedScrollView scrollView = findViewById(R.id.scrollview);
// just make sure that the scroll view is attached to the window,
// or else call this animation inside scroll view post runnable.
ScrollAnimator.create()
.withAnimation(Animations.ANIMATION_ALPHA)
.withInterpolator(Animations.INTERPOLATOR_OVERSHOOT)
.tillDuration(Animations.DURATION_FAST)
.playOnlyOnDownScroll(true)
.animate(scrollView);
In case when the view is not attached and animation didn't worked,
scrollView.post(() -> {
// animate scrollview here
})
If your code already use onScrollChangeListener()
on scrollview, then you must use
this approch to animate it.
Example:
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
ScrollAnimator.create()
.withAnimation(Animations.ANIMATION_ALPHA)
.withInterpolator(Animations.INTERPOLATOR_OVERSHOOT)
.tillDuration(Animations.DURATION_FAST)
.playOnlyOnDownScroll(true)
.animateOnScroll(scrollView, scrollY, oldScrollY);
}
});
Contributions are always welcome!
There is a scope for improvement in this library. What you can always do is you can add more animations and interpolators to this library. To do so, you just need to :-
- Add animation/interpolator constant to Animation class
- Add new case for the animation in switch-case ladder of getAnimation() method.
If you liked my hard work, you can start this library. Moreover, you can submit us your app link to make it appear in the used by section.