viewPager setAdpater 后调用
setSliderTransformDuration(
900); 就可以了
public void setSliderTransformDuration(int duration) {
try {
Field mScroller = ViewPager. class.getDeclaredField( "mScroller");
mScroller.setAccessible( true);
FixedSpeedScroller scroller = new FixedSpeedScroller(getActivity(), null, duration);
mScroller.set( vp_adverse, scroller);
} catch (Exception e) {
e.printStackTrace();
}
}
public class FixedSpeedScroller extends Scroller {
private int mDuration = 1000;
public FixedSpeedScroller(Context context) {
super(context);
}
public FixedSpeedScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
public FixedSpeedScroller(Context context, Interpolator interpolator, int duration) {
this(context, interpolator);
mDuration = duration;
}
@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);
}
}
Field mScroller = ViewPager. class.getDeclaredField( "mScroller");
mScroller.setAccessible( true);
FixedSpeedScroller scroller = new FixedSpeedScroller(getActivity(), null, duration);
mScroller.set( vp_adverse, scroller);
} catch (Exception e) {
e.printStackTrace();
}
}
public class FixedSpeedScroller extends Scroller {
private int mDuration = 1000;
public FixedSpeedScroller(Context context) {
super(context);
}
public FixedSpeedScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
public FixedSpeedScroller(Context context, Interpolator interpolator, int duration) {
this(context, interpolator);
mDuration = duration;
}
@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);
}
}