我正在尝试使用自定义布局的SupportMapFragment,现在以下代码可以工作:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = super.onCreateView(inflater, container, savedInstanceState);
// initMap();
return view;
}
Run Code Online (Sandbox Code Playgroud)
但我想改变onCreateView()方法来膨胀不同的布局,而不是调用super.onCreateView()方法.看起来像这样:
View view = inflater.inflate(R.layout.fragment, container,false);
mMap = (GoogleMap)view.findViewById(R.id.mapview);
Run Code Online (Sandbox Code Playgroud)
但谷歌地图不是view这样我不能将其添加到xml中,如下所示:
<com.google.android.gms.maps.GoogleMap
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)