Gesture OnFling not called in ListView
I need some help with handling the gestures on a listview. I have an videoview that I want to be able to detect left and right swipes on the layout below:
Link to a drawing of the current gesture and what is expected
The onFling method that i used to capture the event is not called
public class OnSwipeTouchListener implements OnTouchListener {
private final GestureDetector gestureDetector;
private FeedAdapter callback;
public OnSwipeTouchListener(Context context, FeedAdapter callback) {
gestureDetector = new GestureDetector(context, new GestureListener());
this.callback = callback;
}
@Override
public boolean onTouch(final View view, final MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}
private final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 30;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
public boolean onSingleTapUp(MotionEvent e) {
Log.v("Tom", "tap");
triggerTouch();
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
boolean result = false;
Log.v("Swipe","is called"); // this is not called when swipe is not perfectly straight
try {
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > SWIPE_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
public void onSwipeRight() {
}
public void onSwipeLeft() {
}
public void triggerTouch() {
}
public void onSwipeBottom() {
}
}
So how to make the onFling be called when user swipes slightly off horizontal?
Thank you for your help!
Tommy
Read more
stackoverflow.comm
No comments:
Post a Comment