Java 在片段中使用google地图支持片段

Java 在片段中使用google地图支持片段,java,android,google-maps,android-fragments,Java,Android,Google Maps,Android Fragments,我目前正在做一个以NavigationDrawer为主要活动的应用程序。所以,在我的应用程序中导航任何其他“活动”都是一个片段,在其中一个片段中,我需要放置一个GoogleMap支持片段。关键是,在我的片段中,我执行getFragmentManager.findframentbyid(R.id.map)它返回null 下面是我的代码的样子 //fragment_home.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLa

我目前正在做一个以NavigationDrawer为主要活动的应用程序。所以,在我的应用程序中导航任何其他“活动”都是一个片段,在其中一个片段中,我需要放置一个GoogleMap支持片段。关键是,在我的片段中,我执行
getFragmentManager.findframentbyid(R.id.map)它返回null

下面是我的代码的样子

//fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
//My HomeFragment
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_home, container, false);

    FragmentManager manager = getFragmentManager();

    SupportMapFragment mapFragment = (SupportMapFragment)manager.findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    return view;
}
//fragment\u home.xml
//我的家庭碎片
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
//为该碎片膨胀布局
视图=充气机。充气(R.layout.fragment\u home,container,false);
FragmentManager=getFragmentManager();
SupportMapFragment mapFragment=(SupportMapFragment)manager.findFragmentById(R.id.map);
getMapAsync(这个);
返回视图;
}
有人知道如何解决这个问题吗?我已经在这个网站和许多其他网站上寻找了解决方案,但我不知道如何将片段存储在我的“父”片段的xml布局中

谢谢你的帮助, 热忱地,
Matthieu Meunier

如果要在
片段中使用
SupportMapFragment
,则不能使用
getFragmentManager
方法。而是使用以下方法

SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);

如果要在
片段中使用
SupportMapFragment
,则不能使用
getFragmentManager
方法。而是使用以下方法

SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);