본문 바로가기

Study/Android

[Android] GestureDetector Top/Bottom/Up/Down

GestureDetectorCompat gestureDetectorCompat 
			= new GestureDetectorCompat(this, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            float angle = (float) Math.toDegrees(Math.atan2(e1.getY() - e2.getY(), e2.getX() - e1.getX()));
            
            if (angle > -45 && angle <= 45) {
                Log.d(DEBUG_TAG, "Right to Left swipe performed");
                return true;
            }

            if (angle >= 135 && angle < 180 || angle < -135 && angle > -180) {
                Log.d(DEBUG_TAG, "Left to Right swipe performed");
                return true;
            }

            if (angle < -45 && angle >= -135) {
                Log.d(DEBUG_TAG, "Up to Down swipe performed");
                return true;
            }

            if (angle > 45 && angle <= 135) {
                Log.d(DEBUG_TAG, "Down to Up swipe performed");
                return true;
            }

            return false;
        }
    });

 

'Study > Android' 카테고리의 다른 글

[Android] Scale Animation  (0) 2019.06.14
[Android] wifi 원격 디버깅  (0) 2019.06.14
[Android] Touch Event + SeekBar  (0) 2019.06.14
[Android] 가로 리스트 뷰  (0) 2019.06.14
[Android] google sign in 연동하기  (0) 2019.06.14