2013-06-02 44 views
0

我正嘗試使用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> 

回答

0

SOLUTION
只有溶液(i找到)是使用片段而不是和在那裏充氣地圖視圖

事情是這樣的:

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