Please tell how to implement double tap for SurfaceView
in Android using gesture detector. Can anybody provide code example?
android.view.SurfaceHolder. Abstract interface to someone holding a display surface. Allows you to control the surface size and format, edit the pixels in the surface, and monitor changes to the surface. This interface is typically available through the SurfaceView class.
In the context of the Android framework, Surface refers to a lower-level drawing surface whose contents are eventually displayed on the user's screen. A SurfaceView is a view in your view hierarchy that has its own separate Surface , as shown in the diagram below. You can draw to it in a separate thread.
You could try following.. actually i tested this and it works pretty well:
1) Extend GestureDetector.SimpleOnGestureListener
and override it's onDoubleTap()
method:
class DoubleTapGestureDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDoubleTap(MotionEvent e) {
Log.d("TAG", "Double Tap Detected ...");
return true;
}
}
2) Instantiate the GestureDetector
:
final GestureDetector mGesDetect = new GestureDetector(this, new DoubleTapGestureDetector());
3) Set an OnTouchListener
on your SurfaceView
, override its onTouch()
method and call the onTouchEvent()
on your GestureDetector
object:
surfview.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mGesDetect.onTouchEvent(event);
return true;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With