OnTouch in MapView only fires the first time

后端 未结 6 885
没有蜡笔的小新
没有蜡笔的小新 2020-12-17 02:04

I\'m trying to implement a double-tap zoom like function in my MapView. The event always fires the first time, but never subsequent times. Below is my code. I have a feeling

相关标签:
6条回答
  • 2020-12-17 02:21

    I was having the same problem - I couldn't drag and scroll the map because it was receiving only ACTION_DOWN events. It can be solved by adding android:clickable="true" to the MapView or by calling mapView.setClickable(true).

    0 讨论(0)
  • 2020-12-17 02:37

    How about using a GestureDetector.OnDoubleTapListener instead of OnTouchListener?

    0 讨论(0)
  • 2020-12-17 02:41

    If you are using this method "mapView.setBuiltInZoomControls(true);" then your touch is working at once .

    Please remove that that line and check I am sure it will work..

    In some case if you want BuiltInZoomControls then you can you OnTouch method of Overlay like as below..

    public class MapOverlay extends Overlay {
    
        public MapOverlay(Context ctx) {super(ctx);}
    
        @Override
        protected void draw(Canvas c, MapView osmv, boolean shadow) { }
    
        @Override
        public boolean onTouchEvent(MotionEvent e, MapView mapView) {
            //Write yout touch code here..
            return false;
        }
    }
    
    0 讨论(0)
  • 2020-12-17 02:43

    Implement the Touch event on the map view instead. That will work!!

        // The onTouch event of the Map itself does not fire!
        // We must implement it on the mapView!!!
        mapView.setOnTouchListener(new OnTouchListener()
        {
            public boolean onTouch(View v, MotionEvent event) 
            {
                // Your code and remember to return true!                
    
                return (true);
            }
        });
    
    0 讨论(0)
  • 2020-12-17 02:44

    Subclass MapView and override dispatchTouchEvent like below and use the subclass instead.

    public class MyMap extends MapView{
    @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
             if (mOnMovedListener!= null) {
                    mOnMovedListener.onMove(ev);
                }
                return super.dispatchTouchEvent(ev);
            }
        private OnMovedListener mOnMovedListener;
    
        public void setOnMovedListener(OnMovedListener mOnMovedListener) {
            this.mOnMovedListener= mOnMovedListener;
        }
    }
    

    register for listener like any other!

    0 讨论(0)
  • 2020-12-17 02:44

    you should at least put

    lasttime=event.getEventTime();
    

    under the

    if (event.getAction() == MotionEvent.ACTION_DOWN) brakes 
    

    while onTouch detect ACTION_UP event of your click. So any time you make a click it is called 2 times

    0 讨论(0)
提交回复
热议问题