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 !
4
- possible duplicate stackoverflow.com/questions/8330187/…Rajesh N– Rajesh N2017-04-25 09:35:28 +00:00Commented Apr 25, 2017 at 9:35
- I have seen it still dosen't work for meMeknessiHamida– MeknessiHamida2017-04-25 09:37:21 +00:00Commented Apr 25, 2017 at 9:37
- 1then try scrollview .setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return false; } });Rajesh N– Rajesh N2017-04-25 09:39:22 +00:00Commented Apr 25, 2017 at 9:39
- Possible duplicate of Detect swipe using onTouchListener in ScrollViewlive-love– live-love2018-11-06 16:53:56 +00:00Commented Nov 6, 2018 at 16:53
Add a comment |
1 Answer
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; } }); 4 Comments
MeknessiHamida
the swipe is not on the scrollview, its on a chart inside the scrollview
Rajesh N
implement same event for chart view as well
Shoeb Siddique
It trigger the swipe left event when i am doing vertical scroll.
Rajesh N
This will conflict with scroll view controller like recycleview etc.