0

I am overriding onTouchEvent in a layout, and want to handle horizontal movement only.

i.e, if right of left swipe happens then I will show next/prev post and if any vertical movement happens then I wont do anything and the parent scrolling will happen.

How can I do this?

switch (e1.getAction()) {
            case MotionEvent.ACTION_DOWN:
                offsetX = 0;
                offsetY = 0;
                startTouchPoint = new Point((int) e1.getX(), (int) e1.getY());
                break;
            case MotionEvent.ACTION_MOVE:
                movement = new Point(Math.abs((int) e1.getX() - startTouchPoint.x), Math.abs((int) e1.getY() - startTouchPoint.y));
                if (movement.y < movement.x) { // Horizontal movement

                    // Custom code to move to prev/next page.
                } else { // Vertical movement
                   // I need android to handle this.
                }

1 Answers1

0

onTouchEvent returns a Boolean value.

Simply return True if the event was handled, false otherwise.

Please see https://developer.android.com/reference/android/view/View.html#onTouchEvent(android.view.MotionEvent) for details.

Chebyr
  • 2,171
  • 1
  • 20
  • 30