Android onFling MotionEvent not change

I'm working on a project and I'm using a ImageView that is moved in onScroll, I recently implemented an onFling to detect swipe but I just saw that when I swipe the picture, the two MotionEvents from the onFling get the same X value using getX(). But that doesn't happen when doing swipe outside the view.

Why can be this happening?
Is there a way to fix it?
Thanks!

This is what I'm trying to implement:

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    final int SWIPE_MIN_DISTANCE = 120;
    final int SWIPE_MAX_OFF_PATH = 250;
    try {

        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH){
            return false;
        }
        // right to left swipe
        if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) > Common.SWIPE_THRESHOLD_VELOCITY) {
            if (Common.search_submissions_ID < Common.search_submissions.length()) {
                Common.search_submissions_ID = Common.search_submissions_ID + 1;
                finish();
                startActivity(getIntent());
            } else {
                //Update
            }
        }
        // left to right swipe
        else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) > Common.SWIPE_THRESHOLD_VELOCITY) {
            if (Common.search_submissions_ID > 0) {
                Common.search_submissions_ID = Common.search_submissions_ID - 1;
                finish();
                startActivity(getIntent());
            }
        }
    } catch (Exception e) {

    }
    return false;
}

PD: SWIPE_THRESHOLD_VELOCITY = 4500

链接地址: http://www.djcxy.com/p/16216.html

上一篇: 在Android中检测多个视图上的手势

下一篇: Android onFling MotionEvent不会更改