修改ViewPager滚动切换的动画时间

来源:互联网 发布:sql server 按天分组 编辑:程序博客网 时间:2024/06/06 05:32

主要用于广告幻灯片viewpager循环滚动


try {            //设置滚动切换的动画时间            Field field = ViewPager.class.getDeclaredField("mScroller");            field.setAccessible(true);            FixedSpeedScroller scroller = new FixedSpeedScroller(gg_vp.getContext(),                    new AccelerateInterpolator());            field.set(gg_vp, scroller);            scroller.setmDuration(400);        } catch (Exception e) {            e.printStackTrace();        }

import android.content.Context;import android.view.animation.Interpolator;import android.widget.Scroller;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 int getmDuration() {        return mDuration;    }    public void setmDuration(int time) {        mDuration = time;    }}


0 0
原创粉丝点击