Can panning/zooming be disabled in an android MapView while allowing users to click on an ItemizedOverlay?

只愿长相守 提交于 2019-12-24 05:22:15

问题


Is there a way of disabling panning/zooming and keeping map overlays clickable?

I am specifically thinking about an ItemizedOverlay that I want to be tappable while denying users from moving around the map's viewport (It's for a game).

I've seen the same question answered but the answer sadly doesn't allow for overlay items to be clicked.

Thanks alot, best regards, Alex


回答1:


I know this question is a little old but I had the same problem and found a workaround, it's not a graceful solution but appears to work.

First you have to create your own map subclass overriding the onTouchEvent handler

public class NonPannableMapView extends MapView {

    public NonPannableMapView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);    
    }

    public NonPannableMapView(Context context, AttributeSet attrs){
        super(context, attrs);
    }

    public NonPannableMapView(Context context, String apiKey) {
         super(context, apiKey);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
          //Handle a move so there is no panning or zoom
          if(ev.getAction() == MotionEvent.ACTION_MOVE)
              return true;
      return super.onTouchEvent(ev);
    }
}

Then it's just a case of changing the MapView reference in your layout to NonPannableMapView.




回答2:


Try this:

mapView.setBuiltInZoomControls(false);

Hope that works! Have fun!



来源:https://stackoverflow.com/questions/6439811/can-panning-zooming-be-disabled-in-an-android-mapview-while-allowing-users-to-cl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!