2

so I tried Zala's code for handling the gestures from this question android how to handle right to left swipe gestures, it works but the problem is my component is inside a scrollview so the gestures sometimes are detected sometimes not, I tried few different codes to solve this scrollview issue still the same behavior. Anyone could help please !

Community
  • 1
  • 1
MeknessiHamida
  • 185
  • 1
  • 8
  • 28
  • possible duplicate http://stackoverflow.com/questions/8330187/gesture-detection-and-scrollview-issue – Rajesh N Apr 25 '17 at 09:35
  • I have seen it still dosen't work for me – MeknessiHamida Apr 25 '17 at 09:37
  • 1
    then try scrollview .setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return false; } }); – Rajesh N Apr 25 '17 at 09:39
  • Possible duplicate of [Detect swipe using onTouchListener in ScrollView](https://stackoverflow.com/questions/16141264/detect-swipe-using-ontouchlistener-in-scrollview) – live-love Nov 06 '18 at 16:53

1 Answers1

7
scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch(event.getAction()){
                    case MotionEvent.ACTION_DOWN:{
                        downX = event.getX();}
                    case MotionEvent.ACTION_UP:{
                        upX = event.getX();

                        float deltaX = downX - upX;

                        if(Math.abs(deltaX)>0){
                            if(deltaX>=0){
                                swipeToRight();
                                return true;
                            }else{
                                swipeToLeft();
                                return  true;
                            }
                        }
                    }
                }

                return false;
            }
});
Rajesh N
  • 6,198
  • 2
  • 47
  • 58