Created
January 17, 2018 16:45
-
-
Save chris-carneiro/38ec5d0c5829997db49c836b7b09ccf5 to your computer and use it in GitHub Desktop.
Endless autoscrolling for viewPager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ObjectAnimator scrollDownSmoothlyIndefinitely(@NonNull WeakReference<NestedScrollView> scrollViewRef, int scrollingDuration) { | |
NestedScrollView scrollView = scrollViewRef.get(); | |
if (scrollView != null) { | |
final ObjectAnimator animScrollDown = ObjectAnimator.ofInt(scrollView, "scrollY", | |
scrollView.getChildAt(0).getHeight()); | |
animScrollDown.setInterpolator(new LinearInterpolator()); | |
animScrollDown.setDuration(scrollingDuration); | |
final ObjectAnimator animScrollToTop = ObjectAnimator.ofInt(scrollView, "scrollY", | |
0); | |
animScrollToTop.setDuration(500); | |
animScrollDown.addListener(new Animator.AnimatorListener() { | |
@Override | |
public void onAnimationStart(Animator animator) { | |
} | |
@Override | |
public void onAnimationEnd(Animator animator) { | |
if (!animScrollToTop.isStarted()) { | |
animScrollToTop.start(); | |
} | |
} | |
@Override | |
public void onAnimationCancel(Animator animator) { | |
} | |
@Override | |
public void onAnimationRepeat(Animator animator) { | |
} | |
}); | |
animScrollToTop.addListener(new Animator.AnimatorListener() { | |
@Override | |
public void onAnimationStart(Animator animator) { | |
} | |
@Override | |
public void onAnimationEnd(Animator animator) { | |
if (!animScrollDown.isStarted()) { | |
animScrollDown.start(); | |
} | |
} | |
@Override | |
public void onAnimationCancel(Animator animator) { | |
} | |
@Override | |
public void onAnimationRepeat(Animator animator) { | |
} | |
}); | |
if (!animScrollDown.isStarted()) { | |
animScrollDown.start(); | |
} | |
return animScrollDown; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment