在Osmdroid地图中禁用滚动

编程入门 行业动态 更新时间:2024-10-27 12:25:23
本文介绍了在Osmdroid地图中禁用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 Osmdroid MapView。即使我设置了

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?

推荐答案

我找到了解决方案。您需要通过设置 OnTouchListener 直接处理触摸事件。例如,

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; } }

更多推荐

在Osmdroid地图中禁用滚动

本文发布于:2023-06-07 22:05:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568611.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   Osmdroid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!