How to add custom controls to MapFragment in Google Maps Android API v2?

后端 未结 5 1369
故里飘歌
故里飘歌 2021-02-01 08:38

I have SupportMapFragment and I need to add custom controls into it for changing a map type. Calling getView(), I get NoSaveStateFramelayout and I don\'t think it is a good idea

5条回答
  •  终归单人心
    2021-02-01 09:26

    I have decided to override onCreateView and encapsulate the map in the code.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
        View mapView = super.onCreateView(inflater, viewGroup, bundle);
        RelativeLayout view = new RelativeLayout(getActivity());
        view.addView(mapView, new RelativeLayout.LayoutParams(-1, -1));
        // working with view
        return view;
    }
    

    And it works as I needed.

提交回复
热议问题