I am trying to have SupportMapFragment with a custom layout, right now the following code works :
@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;
}
But I want to change the onCreateView() method to inflate a different layout, instead of calling the super.onCreateView() method.
To look like something like this:
View view = inflater.inflate(R.layout.fragment, container,false);
mMap = (GoogleMap)view.findViewById(R.id.mapview);
But GoogleMap is not a view so I cannot add it to the xml, like the following way:
<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"
/>
If you want to create a SupportMapFragment with a custom layout, I prefer to extend the
android.support.v4.app.Fragmentfrom the Support Library and inflate your custom XML with thecom.google.android.gms.maps.MapViewand other views there.But be careful to forward the livecycle methods to this
MapViewas quoted here.