问题
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:
- on single tap new bitmap is added on top of background,
- on double tap bitmap at given position is removed,
- on tap&move (like drag&drop) bitmap is moving,
- on press and move surface view is scrolling,
- on pinch out/pinch in surface view is scaling accordingly.
Is this doable only with GestureRezognizer? If not, how to handle all those cases?
回答1:
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.
来源:https://stackoverflow.com/questions/15862705/touch-events-and-gestures-in-surface-view