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

viewpager切换耗时控制

时间:2017-07-19 14:23:33      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:bsp   new   rpo   received   extends   starty   turn   lov   xtend   

原文地址https://my.oschina.net/javalover/blog/179003

public class FixedSpeedScroller extends Scroller {
    private int mDuration = 1500;

    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 setmDuration(int time) {
        mDuration = time;
    }

    public int getmDuration() {
        return mDuration;
    }
}

 

使用

try {
                Field field = ViewPager.class.getDeclaredField("mScroller");
                field.setAccessible(true);
                FixedSpeedScroller scroller = new FixedSpeedScroller(mViewPager.getContext(),
                        new AccelerateInterpolator());
                field.set(mViewPager, scroller);
                scroller.setmDuration(2000);
            } catch (Exception e) {
                LogUtils.e(TAG, "", e);
            }

 

viewpager切换耗时控制

标签:bsp   new   rpo   received   extends   starty   turn   lov   xtend   

原文地址:http://www.cnblogs.com/anni-qianqian/p/7204936.html

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