views:

44

answers:

1

i am using android gallery is there any listener or way i can know which get fired when user start motion, stop motion, slowing down or moving ?

i see you can overide 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 i know if scrolling is going to stop or started ?

A: 

you are in the right way, now based in your display width you will compare the Original Velocity with the Modified Velocity.

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);
}
Jorgesys
I want to know if user user start scroll once after how much time it will get stop, i want to fire action when scroll get stop.
Faisal khan