我试图在地图叠加层上放置一个标记,然后在用户选择可绘制对象时显示一个弹出窗口。问题是事件似乎重叠。当我在标记上点击(ontouch MotionEvent.ACTION_UP 调用)然后一段时间其他标记消失并且我也想在弹出窗口可见时这样做,然后没有一个标记可以被用户拖动。有没有人对如何使这些事件相互排斥有任何建议?
这是地图活动的代码:
@Override
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;
if (action == MotionEvent.ACTION_DOWN) {
for (OverlayItem item : items) {
Point p = new Point(0, 0);
map.getProjection().toPixels(item.getPoint(), p);
if (hitTest(item, marker, x - p.x, y - p.y)) {
result = true;
inDrag = item;
items.remove(inDrag);
populate();
xDragTouchOffset = 0;
yDragTouchOffset = 0;
setDragImagePosition(p.x, p.y);
dragImage.setVisibility(View.VISIBLE);
xDragTouchOffset = x - p.x;
yDragTouchOffset = y - p.y;
Log.e("touch"," out ACTION_DOWN");
// onTap(index);
break;
}
}
} else if (action == MotionEvent.ACTION_MOVE && inDrag != null) {
//
setDragImagePosition(x, y);
Log.e("touch"," out btn");
result = true;
flag = false;
} else if (action == MotionEvent.ACTION_UP && inDrag != null) {
if (mLastMotionEventAction == MotionEvent.ACTION_DOWN){
// SOME TAP ACTIONS ...
dragImage.setVisibility(View.GONE);
GeoPoint pt = map.getProjection().fromPixels(
x - xDragTouchOffset, y - yDragTouchOffset);
OverlayItem toDrop = new OverlayItem(pt, inDrag.getTitle(),
inDrag.getSnippet());
Log.e("touch"," out last" + pt.getLatitudeE6());
items.add(toDrop);
// onTap(pt, map);
// onTap();
populate();
inDrag = null;
result = true;
flag = false;
// if (result) {
//
// }
Log.e("pop up", "pop up");
return false;
} else {
return true;
}
// onTap(index);
}
mLastMotionEventAction = event.getAction();
return (result || super.onTouchEvent(event, mapView));
}
private void setDragImagePosition(int x, int y) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) dragImage
.getLayoutParams();
lp.setMargins(x - xDragImageOffset - xDragTouchOffset, y
- yDragImageOffset - yDragTouchOffset, 0, 0);
dragImage.setLayoutParams(lp);
}
}
我写 onTap 但这个方法不起作用。没有错误。我想处理这两种方法。