Android multi touch and double tap working together for an imageview

ε祈祈猫儿з 提交于 2019-12-06 09:19:11

问题


Hi I have two imageviews in a LinearLayout(Vertical orientation). I am setting setOnTouchListener for both the Imageviews. This way i am able to observe the Multi touch zoom as well as all the dragging of the ImageViews. The problem comes when i try to implement OnDoubletapListener. OnDoubleTapListener works only without the use of setOnTouchListener.

However if i comment the setOnTouchListner then i am able to perform Double Tap..

Can't the two feartures work simultaneously?????

If You want i can provide the source code as well.. Pl Help

Ankit Verma


回答1:


I had also face that same type problem....I solve with this way...

If You using android mutitouch controller http://code.google.com/p/android-multitouch-controller/ for multitouch

and GestureDetector http://www.41post.com/4194/programming/android-detecting-double-tap-events for double tap

than

update this steps in MultiTouchController.java

--> import

  import android.view.GestureDetector.OnDoubleTapListener;

  import android.view.GestureDetector.OnGestureListener;

--> implement

 public class MultiTouchController<T> implements OnGestureListener{

-->

public MultiTouchController(MultiTouchObjectCanvas<T> objectCanvas2, boolean handleSingleTouchEvents) {

           //....

    gd = new GestureDetector(this);

    // set the on Double tap listener
    gd.setOnDoubleTapListener(new OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            // set text color to green
            Log.d("CLICK", "double taped");



            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // if the second tap hadn't been released and it's being moved
            if (e.getAction() == MotionEvent.ACTION_MOVE) {
                Log.d("CLICK", "double tap event ACTION_MOVE");
            } else if (e.getAction() == MotionEvent.ACTION_UP)// user
                                                                // released
                                                                // the
                                                                // screen
            {
                Log.d("CLICK", "double tap event ACTION_UP");
            }
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // set text color to red
            Log.d("CLICK", "single taped");

            return true;
        }
    });

--> set touch event to gd at onTouch(MotionEvent event)

   public boolean onTouchEvent(MotionEvent event) {

    gd.onTouchEvent(event);

    try {

               //.....

Don't change in any other files.

Now test...Hope you solved problem...must reply...




回答2:


Hey I don't know if you are still stuck with the same problem but I found a way to get around it. In fact, I just implement the OnTouchListner for the multitouch events and I measure the time between two calls to ACTION_DOWN. If that time is smaller than a certain value, I consider that this was a double touch and I perform the actions consequently. Hope that helps. If you found a way to implement both the OnTouchListner and the GestureDetector.OnDoubleTapListener please let me know!




回答3:


Please check below link , may be helpful to you ..implements GestureDetector http://android-journey.blogspot.com/2010/01/android-gestures.html

GestureDetector.OnDoubleTapListener {The listener that is used to notify when a double-tap or a confirmed single-tap occur. }



来源:https://stackoverflow.com/questions/4604011/android-multi-touch-and-double-tap-working-together-for-an-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!