goback add

控件一:Gallery之滑动速度的问题

3461 点击·0 回帖
灯火互联
楼主

用Gallery展示图片,遇到一个问题,就是滑动太快,每次轻轻一拨图片,就滑动过去几张,怎么解决呢?
1、直接继承Grallery,重写onFling方法,返回值为false
[java]
@Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        return false;
    }

2、也是重写onFling方法
[java]
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
        return e2.getX() > e1.getX();
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        // e1是按下的事件,e2是抬起的事件
        int keyCode;
        if (isScrollingLeft(e1, e2)) {
            keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
        } else {
            keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
        }
        onKeyDown(keyCode, null);
        return true;
    }


摘自 LonelyRoamer的专栏


喜欢0 评分0