noties / Scrollable

Android scrollable tabs
Apache License 2.0
1.24k stars 229 forks source link

ScrollHeader is not smoothly #56

Closed songtoanht closed 6 years ago

songtoanht commented 7 years ago

When I want top a page, I use scrollTo(0, 0), it back to top without animator. Could you help me it smoothly? Thank you

noties commented 7 years ago

Hey! It's actually pretty easy:

// here `0` means fully expanded, and if `scrollableLayout.getMaxScrollY()` is passed -> fully collapsed
final ValueAnimator animator = scrollableLayout.animateScroll(0);
animator.setDuration(250L); // do not forget to set duration
// here you can modify ValueAnimator to your own needs, like customising interpolator, add
// update listeners, etc
animator.start(); // animation will start

Please note that only one animation can run at a time. ScrollableLayout internally caches returned animator. So, if an animation is requested whilst another one is running, the running one will be cancelled. This also means that each time you should pass all required arguments for an animation as some previous settings will still be present (like interpolators, duration, etc). So, each time you request an animation make sure you instantiate all requirements (and/or clear previous ones). In short it works almost like View deals with ViewPropertyAnimator.

songtoanht commented 6 years ago

I got it. Thank you for your help :+1: