因為要做輪播,但輪播速度過快,導致
需要調整滑動速度
參考以下這個解
http://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);
}
沒有留言:
張貼留言