ViewPager设置自定义滚动时间
程序员文章站
2022-06-09 15:55:30
...
public class ViewPagerScroller extends Scroller {
private int mDuration = 1500;
public ViewPagerScroller(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 setmDuration(int time) {
mDuration = time;
}
public int getmDuration() {
return mDuration;
}
}
下面直接调用上面的方法即可:
scroller.setmDuration(1500);是设置viewpager自定义滚动时间,根据自己的需求进行设置
try { Field field = ViewPager.class.getDeclaredField("mScroller"); field.setAccessible(true);
ViewPagerScroller scroller = new ViewPagerScroller (mViewPager.getContext(),new AccelerateInterpolator()); field.set(mViewPager, scroller); scroller.setmDuration(1500); } catch (Exception e) { }
上一篇: 渠道开发方案怎么写(渠道策划方案PPT)
下一篇: 代理一个手游项目需要花费多少精力?