Disable scrolling in Osmdroid map

纵然是瞬间 提交于 2019-12-08 06:04:00

问题


I have an Osmdroid MapView. Even though I have set

mapView.setClickable(false);
mapView.setFocusable(false);

the map can still be moved around. Is there a simple way to disable all interactions with the map view?


回答1:


I've found a solution. You need to handle the touch events directly by setting a OnTouchListener. For example,

public class MapViewLayout extends RelativeLayout {

    private MapView mapView;

    /**
     * @see #setDetachedMode(boolean)
     */
    private boolean detachedMode;

    // implement initialization of your layout...

    private void setUpMapView() {
       mapView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (detachedMode) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        // if you want to fire another event
                    }

                    // Is detached mode is active all other touch handler
                    // should not be invoked, so just return true
                    return true;
                }

                return false;
            }
        });
    }

    /**
     * Sets the detached mode. In detached mode no interactions will be passed to the map, the map
     * will be static (no movement, no zooming, etc).
     *
     * @param detachedMode
     */
    public void setDetachedMode(boolean detachedMode) {
        this.detachedMode = detachedMode;
    }
}



回答2:


A simple solution is to do like @Schrieveslaach but with the mapView:

mapView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});



回答3:


You could try:

mapView.setEnabled(false); 

Which should disable all interactions with the map view



来源:https://stackoverflow.com/questions/14409838/disable-scrolling-in-osmdroid-map

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