你是在正确的方式,现在根据你的显示宽度,你将比较原始速度与修改后的速度。
private float modifiedVelocityX;
private void init() {
Display display = ((WindowManager) getContext().getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Log.i(TAG, "Width = " + display.getWidth() + " Height = " + display.getHeight());
modifiedVelocityX = (float) (width * 1.0); //*** 1.0 = Velocity Factor.
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float mod = velocityX < 0 ? -modifiedVelocityX : modifiedVelocityX;
if (getSelectedItemPosition() == 1 || getSelectedItemPosition() == getAdapter().getCount() - 2) {
mod = velocityX < 0 ? -1 : 1;
}
Log.i(TAG, "Original Velocity X was " + velocityX + " now my Modified Velocity is " + mod);
return super.onFling(e1, e2, mod, velocityY);
}