I\'m writing my own image viewer that enables users to swipe left\\right to see the next\\previous image. I want to animate the image change according to the fling velocity.
I had a similar problem. Instead of working directly with the max and min fling velocities from ViewConfiguration
, you can normalize the velocity to a value between 0 and 1.
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float maxFlingVelocity = ViewConfiguration.get(mContext).getScaledMaximumFlingVelocity();
float velocityPercentX = velocityX / maxFlingVelocity; // the percent is a value in the range of (0, 1]
float normalizedVelocityX = velocityPercentX * PIXELS_PER_SECOND; // where PIXELS_PER_SECOND is a device-independent measurement
In other words, velocityPercentX
gives you the "power" of the fling as a percent, and normalizedVelocityX
is the velocity in terms of your application logic (such as an image width in device-independent pixels).