Reputation: 727
I have a ViewPager component, and inside the fragment, there is a WebView component, I want to detect user's tap on screen, and at the same time, user can swipe also.
Currently I am settings the onTouchListener on ViewPager like this: vPager.setOnTouchListener(new View.OnTouchListener() { float oldX = 0, newX = 0, sens = 5;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
oldX = event.getX();
break;
case MotionEvent.ACTION_UP:
newX = event.getX();
if (Math.abs(oldX - newX) < sens) {
tap();
return true;
}
oldX = 0;
newX = 0;
break;
}
return false;
}
});
I find the listener is triggered only when I swipe left and right, when I swipe up and down, it's not triggered. I am swiping on the WebView component, and it has long content which need scroll.
Upvotes: 1
Views: 1967
Reputation: 1287
You're looking only for the X, up and down moves on the Y axis
Upvotes: 1