I am using a ScrollView in a layout and I need to control speed of scrolling in scrollview.already use manythings.like a object animator ,timer but those are doesn't help me.then how can i control (or) set limited speed on scrolling in scrollview on android.
Asked
Active
Viewed 2,082 times
1
-
Here this question already been asked like [Reduce speed of smooth scroll in scroll view](http://stackoverflow.com/questions/8642677/reduce-speed-of-smooth-scroll-in-scroll-view), are you asking for the same? β sodhankit Mar 04 '17 at 12:19
-
but that's not a proper solution for my question.above link answer work on "Autoscroll" not control the speed of scroll.i already try this.it not working to control the speed...when user scroll... β Mar 04 '17 at 12:25
2 Answers
0
This works for ViewPager
, Never tried for ScrollView
public class FixedSpeedScroller extends OverScroller {
private int mDuration = 2000;
public FixedSpeedScroller(Context context) {
super(context);
}
public FixedSpeedScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
// Ignore received duration, use fixed one instead
super.startScroll(startX, startY, dx, dy, mDuration);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy) {
// Ignore received duration, use fixed one instead
super.startScroll(startX, startY, dx, dy, mDuration);
}
public void setFixedDuration(int duration) {
this.mDuration = duration;
}
}
How to use -
try {
Field _mScroller = ScrollView.class.getDeclaredField("mScroller");
_mScroller.setAccessible(true);
FixedSpeedScroller scroller = new FixedSpeedScroller(mPager.getContext(), new AccelerateDecelerateInterpolator());
scroller.setFixedDuration(600);
_mScroller.set(mScrollView, scroller);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
Log.e("TAG", "Scroller exception" +e.getLocalizedMessage());
}
Give it a try.

Paresh P.
- 6,677
- 1
- 14
- 26
-
Not a good practice. just use above code, let me know what happens, Is firing an exception or what? β Paresh P. Mar 04 '17 at 12:27
0
How to control Android ListView scrolling speed
You can control the scrolling speed of an Android ListView using code like this in a Fragment:
@Override
public void onStart() {
super.onStart();
// scroll speed decreases as friction increases. a value of 2 worked
// well in an emulator; you need to test it on a real device
getListView().setFriction(ViewConfiguration.getScrollFriction() * 2);
}
Default ListView scroll speed is too fast by default, and as a result, itβs hard on the eyes when you scroll through a lot of items

sodhankit
- 1,138
- 1
- 14
- 26