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 !
Asked
Active
Viewed 3,379 times
2
-
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
-
1then 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 Answers
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
-
the swipe is not on the scrollview, its on a chart inside the scrollview – MeknessiHamida Apr 25 '17 at 10:34
-
-
1It trigger the swipe left event when i am doing vertical scroll. – Shoeb Siddique Jun 28 '18 at 10:35
-