我知道这里有一些Mapsforge fragment 的修补程序:https://code.google.com/p/mapsforge/issues/detail?id=177。但是我不确定如何使用它。
到目前为止,这是我已经实现的:
public class TOfflineMapViewFragment extends SherlockFragment{
MapView myOpenMapView;
//other codes here...
public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState) {
view = inflator.inflate(R.layout.offline_map_activity, container, false);
myOpenMapView = (MapView) view.findViewById(R.id.openmapview);
myOpenMapView.setMapFile(new File(Environment.getExternalStorageDirectory().toString() +
"/offlineMap/singapore.map");
return view;
}
}
这是我的xml文件:
<LinearLayout 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"
android:orientation="vertical" >
<org.mapsforge.android.maps.MapView
android:id="@+id/openmapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
我收到此错误:
03-19 15:51:04.243: E/AndroidRuntime(10395): FATAL EXCEPTION: main
03-19 15:51:04.243: E/AndroidRuntime(10395): android.view.InflateException: Binary XML file line #6: Error inflating class org.mapsforge.android.maps.MapView
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-19 15:51:04.243: E/AndroidRuntime(10395): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-19 15:51:04.243: E/AndroidRuntime(10395): at com.fragments.TOfflineMapViewFragment.onCreateView(TOfflineMapViewFragment.java:76)
这有什么问题?
最佳答案
加
AndroidGraphicFactory.createInstance(getActivity().getApplication());
在重写onCreate()为我工作