地图不会滚动

时间:2013-06-02 08:22:55

标签: android dictionary osmdroid

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

这是代码:
活动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>

2 个答案:

答案 0 :(得分:1)

删除

android:clickable="true"
来自MapView的

。另请参阅Unable to pan or move the osmdroid map

答案 1 :(得分: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;
}