Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce speed of smooth scroll in scroll view [duplicate]

I have a scroll View. I performed smooth-scroll.using smoothScrollBy().It all works fine, but I want to change the duration of the smooth-scroll. Smooth-scroll happens very fast and user is not understanding what happened.Please help me reduce smooth-scroll speed?

like image 795
ShineDown Avatar asked Dec 27 '11 08:12

ShineDown


2 Answers

The simple answer is just to replace

scrollView.smoothScrollTo(0, scrollTo); 

with

ObjectAnimator.ofInt(scrollView, "scrollY",  scrollTo).setDuration(duration).start(); 

where duration is the time in milliseconds you want it to take.

like image 173
365SplendidSuns Avatar answered Oct 07 '22 01:10

365SplendidSuns


Try the following code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {     ValueAnimator realSmoothScrollAnimation =          ValueAnimator.ofInt(parentScrollView.getScrollY(), targetScrollY);     realSmoothScrollAnimation.setDuration(500);     realSmoothScrollAnimation.addUpdateListener(new AnimatorUpdateListener()     {         @Override         public void onAnimationUpdate(ValueAnimator animation)         {             int scrollTo = (Integer) animation.getAnimatedValue();             parentScrollView.scrollTo(0, scrollTo);         }     });      realSmoothScrollAnimation.start(); } else {     parentScrollView.smoothScrollTo(0, targetScrollY); } 
like image 27
Muzikant Avatar answered Oct 07 '22 03:10

Muzikant