MapView-禁止拖动,但允许缩放 [英] MapView - Disable dragging around, but allow zooming
问题描述
我有一个ViewPager,里面有3个片段,在最右边,我想显示一个MapView-到目前为止运行良好.但是我想禁用它的拖动功能,但仍然允许用户使用固定的中心放大/缩小.如果允许用户拖动地图,则它会与Viewpager滚动功能混为一谈. 试图禁用可点击+聚焦,但是-当然-不再缩放.
I have a ViewPager with 3 fragments inside, on the outer right I want to display a MapView - working fine so far. But I'd like to disable dragging it around, but still let the user zoom in / out - with a fixed center. If the user would be allowed to drag the map around, it messes with the viewpager scrolling abilities. Tried to disable clickable + focusable but - of course - no zooming anymore..
在stackoverflow上查看了其他问题,但到目前为止,没有一个提供有效的解决方案.
Looked at other questions here at stackoverflow but none provided a working solution so far..
谢谢!
推荐答案
忽略我到目前为止所说的一切(这就是我编辑答案的原因),而是在MapActivity类中使用以下代码(它可以正常工作,只需尝试一下!):
Ignore everything I've said so far (which is why I've edited my answer), instead use the following code in your MapActivity class(it works perfectly, just tried it!):
final GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
final MapController mapController = mapView.getController();
mapController.animateTo(point);
mapController.setZoom(6);
mapView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if(arg1.getAction() == MotionEvent.ACTION_UP)
{
mapController.setCenter(point);
return true;
}
if(arg1.getPointerCount() > 1)
{
mapController.setCenter(point);
return false;
}
else
{
return true;
}
}
});
这篇关于MapView-禁止拖动,但允许缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!