0

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

PepeF
  • 1
  • 2
  • "Same X" means "Touched position in ImageView" I think.. (No change inside, as image moves to cancel the motion.) – Toris Oct 02 '16 at 12:24
  • Is there a way to prevent that or detect the background position? – PepeF Oct 02 '16 at 12:34
  • Get relative position to the parent view of ImageView and calc from it. Or.. cover with another view not moving with ImageView and use it to get the position. – Toris Oct 02 '16 at 12:36
  • Ok thnks, I fixed it! – PepeF Oct 02 '16 at 13:53

0 Answers0