Android 将覆盖添加到MapView后没有滚动
我现在正在解决以下问题: 我在地图视图中添加了一个简单的覆盖图。它没有画任何东西,只是一个帮助覆盖,用于检测滚动是否结束(请参阅) 以下是它的代码:Android 将覆盖添加到MapView后没有滚动,android,overlay,android-mapview,Android,Overlay,Android Mapview,我现在正在解决以下问题: 我在地图视图中添加了一个简单的覆盖图。它没有画任何东西,只是一个帮助覆盖,用于检测滚动是否结束(请参阅) 以下是它的代码: public class ScrollDetectionOverlay extends Overlay { private static GeoPoint lastLatLon = new GeoPoint(0, 0); private static GeoPoint currLatLon; protected boole
public class ScrollDetectionOverlay extends Overlay
{
private static GeoPoint lastLatLon = new GeoPoint(0, 0);
private static GeoPoint currLatLon;
protected boolean isMapMoving = false;
private MapScrollingFinishedListener listener = null;
public void setListener(MapScrollingFinishedListener listener)
{
this.listener = listener;
}
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView)
{
super.onTouchEvent(e, mapView);
if (e.getAction() == MotionEvent.ACTION_UP)
{
isMapMoving = true;
}
return true;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, shadow);
if (!shadow)
{
if (isMapMoving)
{
currLatLon = mapView.getProjection().fromPixels(0, 0);
if (currLatLon.equals(lastLatLon))
{
isMapMoving = false;
listener.onScrollingFinished();
}
else
{
lastLatLon = currLatLon;
}
}
}
}
}
如果我将此覆盖添加到地图视图,我将无法再滚动地图。以下是用于在地图视图中添加和删除覆盖的代码:
@Override
protected void onResume()
{
super.onResume();
if (!getMapView().getOverlays().contains(scrollDetectionOverlay))
{
scrollDetectionOverlay = new ScrollDetectionOverlay();
scrollDetectionOverlay.setListener(this);
getMapView().getOverlays().add(scrollDetectionOverlay);
}
}
@Override
protected void onPause()
{
super.onPause();
if (getMapView().getOverlays().contains(scrollDetectionOverlay))
{
getMapView().getOverlays().remove(scrollDetectionOverlay);
scrollDetectionOverlay = null;
}
}
我怎么了
还有一件事我注意到了。覆盖的draw方法将被调用,调用,调用,而用户不做任何事情。有什么原因吗
谢谢。您将在覆盖的触摸事件中返回
true
。当返回true时,触摸事件停止向下层叠到下部视图。因此,您的MapView
永远不会收到它。你只想在触摸被完全处理,你不想做更多的事情的情况下这样做。如果要移动映射,可以尝试将return语句更改为returnsuper.onTouchEvent(e,mapView)代码>是的,我刚才看到了。谢谢你,迪夫@MurVotema我会更新我的答案以确保完整性。