/** 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;
// TouchDown時のタッチ座標とTouchUp時の座標を比較しどちらにフリックしたか判定
if ((Math.abs(dx) > 1)) {
if (dx > 0) {
Log.d(MainActivity.class.getSimpleName(), "右へフリック"+dx);
} else {
Log.d(MainActivity.class.getSimpleName(), "左へフリック"+dx);
}
}
break;
default:
break;
}
mPreviousTouchPointX = touchX;
return false;
}
});
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme