在Osmdroid地图中禁用滚动 [英] Disable scrolling in Osmdroid map
本文介绍了在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地图中禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文