How to implement a double tap to view the surface in android

Tell us how to implement double-tapping for SurfaceView in Android using a gesture detector. Can someone provide some sample code?

+7
source share
1 answer

You can try the following .. in fact I tested this and it works very well:

1) Extend GestureDetector.SimpleOnGestureListener and override the onDoubleTap() method:

  class DoubleTapGestureDetector extends GestureDetector.SimpleOnGestureListener { @Override public boolean onDoubleTap(MotionEvent e) { Log.d("TAG", "Double Tap Detected ..."); return true; } } 

2) Create an instance of the GestureDetector :

 final GestureDetector mGesDetect = new GestureDetector(this, new DoubleTapGestureDetector()); 

3) Install OnTouchListener on SurfaceView , override its onTouch() method and call onTouchEvent() on your GestureDetector object:

  surfview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { mGesDetect.onTouchEvent(event); return true; } }); 
+15
source

All Articles