ErrorxCode / ScrollAnimator

Animate your Scrollview, Recyclerview or listview scrolling with a nice animation using this awesome library.

Home Page:https://xcoder.tk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ScrollAnimator ~ Animify library

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.

Screenshots

demo.gif.mp4

Features

  • Easy 2 use, builder pattern.
  • Supports ListView, RecyclerView and ScrollView
  • Supports Fade animation
  • Supports Sliding animation
  • Supports Rotating animation
  • Supports Dropping animation

Implementation

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'
	}

Usage/Examples

Simple Usage

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.

Advance Usage

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.

Custom animations

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.

Full Example

Using on RecyclerView/ListView

listView.setAdapter(adapter);
ScrollAnimator.create()
        .withAnimation(Animations.ANIMATION_ALPHA)
        .withInterpolator(Animations.INTERPOLATOR_OVERSHOOT)
        .tillDuration(Animations.DURATION_FAST)
        .playOnlyOnDownScroll(true)
        .animate(litview);

Using on Scrollview/NestedScrollView

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
})

Using with onScrollChangeListener

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);
    }
});

Contributing

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.

That's it

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.

About

Animate your Scrollview, Recyclerview or listview scrolling with a nice animation using this awesome library.

https://xcoder.tk

License:Apache License 2.0


Languages

Language:Java 100.0%