开发者

android image gallery start moving or slowing down and stopped moving

开发者 https://www.devze.com 2023-01-04 22:51 出处:网络
i am using android 开发者_如何学Cgallery is there any listener or way i can know which get fired when user start motion, stop motion, slowing down or moving ?

i am using android 开发者_如何学Cgallery 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 ?


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

精彩评论

暂无评论...
验证码 换一张
取 消