码迷,mamicode.com
首页 > 其他好文 > 详细

改变ViewPager滑动速度

时间:2015-03-20 10:55:12      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:android   android应用   

代码如下:

try {
Interpolator sInterpolator = new AccelerateInterpolator();
Field mScroller = ViewPager.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);
FixedSpeedScroller scroller = new FixedSpeedScroller(
mViewPager.getContext(), sInterpolator);
mScroller.set(mViewPager, scroller);
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


FixedSpeedScroller类的代码:

@SuppressLint("NewApi")
public class FixedSpeedScroller extends Scroller {


private int mDuration = 400;//滑动所用时间


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);
}


}

改变ViewPager滑动速度

标签:android   android应用   

原文地址:http://blog.csdn.net/android0120/article/details/44487899

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!