android原生的viewpager默认不支持自定义滑动速度,直接复制FixedSpeedScroller 类使用即可:
#####使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

controlViewPagerSpeed(this,splash_viewpager,400);//毫秒 速度
// 自定义viewpager滑动速度
private void controlViewPagerSpeed(Context context, ViewPager viewpager, int DurationSwitch) {
try {
Field mField;
mField = ViewPager.class.getDeclaredField("mScroller");
mField.setAccessible(true);
FixedSpeedScroller mScroller =
new FixedSpeedScroller(context, new AccelerateInterpolator());
mScroller.setmDuration(DurationSwitch);
mField.set(viewpager, mScroller);
} catch (Exception e) {
e.printStackTrace();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import android.content.Context;
import android.view.animation.Interpolator;
import android.widget.Scroller;

/**
* Created by tyl
* 2018/9/30/030
* Describe:
*/
public class FixedSpeedScroller extends Scroller {

private int mDuration = 1500; // 默认滑动速度 1500ms

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

/**
* set animation time
*
* @param time
*/
public void setmDuration(int time) {
mDuration = time;
}

/**
* get current animation time
*
* @return
*/
public int getmDuration() {
return mDuration;
}
}