0

我正在尝试使用 osmdroid 库创建一个简单的地图活动
地图显示很好,但它不会滚动。我无法弄清楚问题是什么。

这是代码:
Activity onCreate 方法

    setContentView(R.layout.activity_main);
    final MapView mapView = (MapView)findViewById(R.id.map);

    mapView.setBuiltInZoomControls(true);

    mapView.getController().setZoom(10);

    mapView.getController().setCenter(new GeoPoint(52.221, 6.893));

    ZoomControls mZoomControls = (ZoomControls)findViewById(R.id.zoomControls);
    mZoomControls.setOnZoomInClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mapView.getController().zoomIn();
        }
    });
    mZoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mapView.getController().zoomOut();
        }
    });

和xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >


<org.osmdroid.views.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"/>

<ZoomControls
    android:id="@+id/zoomControls"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="10dp" />

</RelativeLayout>
4

2 回答 2

1

消除

android:clickable="true"

从您的地图视图。另请参阅无法平移或移动 osmdroid 地图

于 2013-06-03T14:38:29.390 回答
0

解决方案
唯一的解决方案(我发现)是使用片段代替并在那里膨胀地图视图

像这样的东西:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mResourceProxy = new ResourceProxyImpl(inflater.getContext()
            .getApplicationContext());
    mMapView = new MapView(inflater.getContext(), 256, mResourceProxy);
    mMapView.setUseSafeCanvas(true);
    mMapView.setBuiltInZoomControls(true);
    mMapView.setMultiTouchControls(true);
    mMapView.getController().setZoom(10); //set initial zoom-level, depends on your need
    mMapView.getController().setCenter(new GeoPoint(52.221, 6.893));
    return mMapView;
}
于 2013-06-02T09:29:41.153 回答