Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SupportMapFragment with a custom layout, possible?

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"
    />
like image 840
meh Avatar asked Dec 03 '22 01:12

meh


1 Answers

If you want to create a SupportMapFragment with a custom layout, I prefer to extend the android.support.v4.app.Fragment from the Support Library and inflate your custom XML with the com.google.android.gms.maps.MapView and other views there.

But be careful to forward the livecycle methods to this MapView as quoted here.

like image 63
Greeny Avatar answered Dec 23 '22 05:12

Greeny