Search code examples
javaandroidviewspacegesture

Gesture Detection for Specific View


Added a spaceView that doesn't cover all of the layout. And I want gesture detection work for only that view.

Couldn't do much but here is my codes:

space = findViewById(R.id.space);
        this.gDetector = new GestureDetectorCompat(this, this);
        gDetector.setOnDoubleTapListener(this);

Solution

  • The onTouchEvent in Android lets you do so. You can add whatever you want to do in that event.

    As per Android Studio's official site, onTouchEvent() is described as ...

    When a user places one or more fingers on the screen, this triggers the callback onTouchEvent() on the View that received the touch events. For each sequence of touch events (position, pressure, size, addition of another finger, etc.) that is ultimately identified as a gesture, onTouchEvent() is fired several times.

    Here's the official link to you for further help

    Hope this helps...