Android Image Gallery will start to move or slow down and stop moving

I am using an android gallery, is there any listener or way that I can know that is triggered when the user starts moving, stops moving, slows down or moves?

I see that you can override the following method

@Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        return super.onFling(e1, e2, velocityX, velocityY);
    }

but how do you know if scrolling will stop or start?

+3
source share
1 answer

you are in the right direction, now based on the width of the screen you are comparing the speed of the original with the changed speed.

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

Source: https://habr.com/ru/post/1751360/


All Articles