有添加到叠加后MapView类没有滚动 [英] There is no scroll after adding an Overlay to MapView
问题描述
我现在有如下的问题战斗:
我简单的重叠添加到我的MapView。它不画任何东西,它只是用于检测滚动帮助叠加结束(见<一href=\"http://stackoverflow.com/questions/4351748/knowing-when-map-has-stopped-scrolling-like-moveend-in-javascript-api/7443880#7443880\">response)
I'm fighting with following problem now: I add a simple overlay to my mapview. It doesn't draw anything, it is just a help overlay for detecting scroll is ended (see response)
下面是它的code:
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;
}
}
}
}
}
如果我加入这个叠加到我的MapView类,我不能再滚动地图。下面是code添加和的MapView覆盖去除:
If I'm adding this overlay to my mapview, I can't scroll the map anymore. Below is the code for adding and removing of the overlay from the mapview:
@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;
}
}
什么是我错了?
和另一件事我注意到了。叠加的拉方法将被调用,叫,叫,无需用户做任何事情。有些理由吧?
And another thing I noticed. The draw-method of overlay will be called, and called, and called, without user does anything. Some reason for it?
感谢您。
推荐答案
您正在返回真正
上叠加的触摸事件。当你返回true,触摸事件停止级联下降到较低的意见。因此,你的图形页面
永远不会收到它。您只希望这样做,如果触摸已经完全处理,你不想做任何事情更多。如果你想在地图移动,你可以尝试改变return语句返回super.onTouchEvent(即图形页面);
You're returning true
on the touch event for the overlay. When you return true, the touch event stops cascading down to the lower views. Thus, your MapView
never receives it. You only want to do that if the touch has been completely handled and you don't want to do anything more. If you want the map to move, you may try changing the return statement to return super.onTouchEvent(e, mapView);
这篇关于有添加到叠加后MapView类没有滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!