如何让数字选择器滚动/速度更快?目前从00分钟到59分钟需要付出很多努力。我已经尝试了Slowing speed of Viewpager controller in android的一些示例,并将其与数字选择器相对应,但我没有看到任何差异。
try {
Field mScroller;
mScroller = NumberPicker.class.getDeclaredField("mFlingScroller");
mScroller.setAccessible(true);
FixedSpeedScroller scroller = new FixedSpeedScroller(getContext(),null,true);
// scroller.setFixedDuration(5000);
// scrollBy(0,1500);
Log.v("Scroller",""+mScroller); //getting the mFlingScroller field
mScroller.set(this, scroller);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
public class FixedSpeedScroller extends Scroller {
private int mDuration = 10;
public FixedSpeedScroller(Context context) {
super(context);
}
public FixedSpeedScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
public FixedSpeedScroller(Context context, Interpolator interpolator, boolean flywheel) {
super(context, interpolator, flywheel);
}
@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);
}
}
我将mDuration降低到低于示例(5000)的值。但仍然没有希望。一些帮助将不胜感激。提前致谢!!! :)