0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PagerViewで左右どちらにフリックしたか判定する方法

Posted at
    /** 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;
        }
    });
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?