小弟杂做的一个地图项目需要在地图上实现拖拽 小弟目前的做法是在我的ItemizedOverlay
中复写onTouchEvent 但是问题就来 复写onTouchEvent 之后 我点击Map上任意地方都会导致事件的触发 而变成点击屏幕上任何地方都是移动这个图标 导致地图无法移动 请各位做过的大侠给点思路package com.mari.mapxy.PositionOverlay;import java.util.ArrayList;
import java.util.List;import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;
import com.mari.mapxy.R;public class PositionOverlay extends ItemizedOverlay {
        private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
        private boolean moveMarker = true;
        private Context context;
        private int centerX=158;
        private int centerY=190;
        public PositionOverlay(Drawable defaultMarker, Context context) {
                super(boundCenterBottom(defaultMarker));
                this.context = context;
        }        @Override
        protected OverlayItem createItem(int arg0) {
                // TODO Auto-generated method stub
                return mOverlays.get(arg0);
        }        @Override
        public int size() {                return mOverlays.size();
        }        /*
         * (non-Javadoc)
         * 
         * @see
         * com.google.android.maps.ItemizedOverlay#onTouchEvent(android.view.MotionEvent
         * , com.google.android.maps.MapView)
         */        public boolean onTouchEvent(MotionEvent e, MapView map) {
                System.out.println("----------"+e.getDeviceId()+"|||"+e.getAction()+"||"+e.getPressure());
                System.out.println("x"+e.getX()+"              y"+e.getY());
                int Action = e.getAction();                if (Action == MotionEvent.ACTION_UP) {
                        moveMarker = false;
                        System.out.println("is up");
                        return true;
                } else if (Action == MotionEvent.ACTION_DOWN) {
                        // moveMarker = true;
                        System.out.println("downs");
                        
                } else if (Action == MotionEvent.ACTION_MOVE||e.getDeviceId()==2) {
                                if(moveMarker){
                                Projection proj = map.getProjection();
                                GeoPoint loc = proj.fromPixels((int) e.getX(), (int) e.getY());
                                map.getOverlays().remove(this);
                                placeMarker(loc,map);
                                }
                        }
                        
        
                return true;
        }        /* (non-Javadoc)
         * @see com.google.android.maps.ItemizedOverlay#onTap(com.google.android.maps.GeoPoint, com.google.android.maps.MapView)
         */
        @Override
        public boolean onTap(GeoPoint p, MapView mapView) {
                
                System.out.println("is me onClick--->"+p);
                return super.onTap(p, mapView);
        }        public void addOverlays(OverlayItem item) {
                mOverlays.add(item);
                populate();
        }
}
}