user919534
user919534

Reputation: 21

Touch events and gestures in surface view

Can anybody point me to some classes or suggest anything for the following case?

I have SurfaceView which has a background image, on top of which I wish to paint other bitmaps. I would like to support following operations:

Is this doable only with GestureRezognizer? If not, how to handle all those cases?

Upvotes: 2

Views: 5743

Answers (1)

Jack Stafford
Jack Stafford

Reputation: 86

To handle touch input, override onTouchEvent in your class that extends SurfaceView to handle a MotionEvent. Here is a sample code that gets the screen position when a user first touches the screen.

@Override    
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        touchX = event.getX();
        touchY = event.getY();
    }
    return true;
}

More information about the MotionEvent object can be found on the Android Developers website.

Upvotes: 2

Related Questions