android getActivity().getSupportFragmentManager().findFragmentById为空

android getActivity().getSupportFragmentManager().findFragmentById为空,android,android-fragments,android-maps,android-maps-v2,Android,Android Fragments,Android Maps,Android Maps V2,我正在尝试加载一个带有com.google.android.gms.maps.SupportMapFragment的映射,但findFragmentById中的值为null 我的xml片段文件: <fragment android:id="@+id/map" android:layout_width="wrap_content" android:layout_height="wrap_content" class="com.google.android.gm

我正在尝试加载一个带有com.google.android.gms.maps.SupportMapFragment的映射,但findFragmentById中的值为null

我的xml片段文件:

<fragment
    android:id="@+id/map"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    class="com.google.android.gms.maps.SupportMapFragment" />
地图片段:

MyMapFragment extends android.support.v4.app.Fragment{
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        SupportMapFragment smf = (SupportMapFragment)  getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
        //here smf is null
    }
}

注意:当版面包含片段时,不能将版面膨胀为片段。嵌套片段仅在动态添加到片段时才受支持

此外,在玩嵌套片段时,请使用
getChildFragmentManager()

检查此链接
MyMapFragment extends android.support.v4.app.Fragment{
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        SupportMapFragment smf = (SupportMapFragment)  getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
        //here smf is null
    }
}