中调用它们
当膨胀这个时,我得到一个android.inflate.Exception.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="***"
/>
这个类扩展.xml(fragment_b.xml)
public class BFragment extends Fragment {
private MapView mMapView;
private GoogleMap googleMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
View v = inflater.inflate(R.layout.fragment_b, container, false);
mMapView = (MapView) v.findViewById(R.id.map);
mMapView.onCreate(savedInstanceState);
mMapView.onResume();//needed to get the map to display immediately
try {
MapsInitializer.initialize(this.getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
googleMap = mMapView.getMap();
return v;
}
}
我用.xml做了很多尝试,但都没有结果。
您不是在混合map api V1
和map api V2
实现吗?
这是地图v1:
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="***"
/>
这就是地图api V2的样子:
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
由于您在XML中创建了map_v1的实例,因此不允许调用onCreate()
和onResume()
,但必须对map_v2
执行此操作。
此外,您还应该记住,在map_v2
中,当活动/碎片生命周期中发生适当的事件时,您必须仅调用onCreate()
、onResume()
。。。因此,您必须仅从您的活动/片段onCreate
和onResume