这是我的 OnTouch 代码。我有另一个 onTap 方法来显示弹出窗口。但是,它不会被触发,因为 OnTouch 在 OnTap 上重叠。因此,如何将此 OnTouchEvent 函数转换为 OnTap。因为,如果我删除这个 onTouch 函数,我将无法拖动标记。
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
final int action=event.getAction();
final int x=(int)event.getX();
final int y=(int)event.getY();
boolean result=false;
p = map.getProjection().fromPixels(x, y);
newP = p;
if (action==MotionEvent.ACTION_DOWN) {
for (OverlayItem item : items) {
Point pa=new Point(0,0);
map.getProjection().toPixels(item.getPoint(), pa);
//I maintain the hitTest's bounds so you can still
//press near the marker
if (hitTest(item, marker, x-pa.x, y-pa.y)) {
result=true;
inDrag=item;
items.remove(inDrag);
populate();
//Instead of using the DragImageOffSet and DragTouchOffSet
//I use the x and y coordenates from the Point
setDragImagePosition1(x, y);
dragImage.setVisibility(View.VISIBLE);
break;
}
}
}
else if (action==MotionEvent.ACTION_MOVE && inDrag!=null) {
setDragImagePosition1(x, y);
result=true;
}
else if (action==MotionEvent.ACTION_UP && inDrag!=null) {
dragImage.setVisibility(View.GONE);
//I get the geopoint without using any OffSet, directly with the
//Point coordenates
p=map.getProjection().fromPixels(x,y);
OverlayItem toDrop=new OverlayItem(p, inDrag.getTitle(),
inDrag.getSnippet());
Drawable orig = inDrag.getMarker(0);
//In my case I had down heading Arrows as markers, so I wanted my
//bounds to be at the center bottom
if( orig != null)
toDrop.setMarker(boundCenterBottom(orig));
items.add(toDrop);
populate();
inDrag=null;
result=true;
}
return(result || super.onTouchEvent(event, mapView));
}
private void setDragImagePosition1(int x, int y) {
RelativeLayout.LayoutParams lp=
(RelativeLayout.LayoutParams)dragImage.getLayoutParams();
//Instead of using OffSet I use the Point coordenates.
//I want my arrow to appear pointing to the point I am moving, so
//I set the margins as the Point coordenates minus the Height and half the
//width of my arrow.
lp.setMargins(x-(dragImage.getWidth()/2),y-dragImage.getHeight(), 0, 0);
dragImage.setLayoutParams(lp);
}