/ ** Coordinates before Touch * / private boolean mIsPagerViewTouchDown = false;
pager.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float touchX = event.getX();
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
mPreviousTouchPointX = touchX;
break;
case MotionEvent.ACTION_UP:
float dx = touchX - mPreviousTouchPointX;
// Compare the touch coordinates at TouchDown and the coordinates at TouchUp to determine which one you flicked if ((Math.abs(dx) > 1)) { if (dx > 0) { Log.d (MainActivity.class.getSimpleName (), "flick right" + dx); } else { Log.d (MainActivity.class.getSimpleName (), "Flick left" + dx); } } break; default: break; }
mPreviousTouchPointX = touchX;
return false;
}
});
Recommended Posts