1.在父的Fragment中定义xml,主要给子Fragment占位
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_loading"
android:background="@drawable/portrait_bg"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/discovery_container"
android:background="@color/catalyst_redbox_background"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:id="@+id/loadedRN"
android:text="加载RNContext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
2.代码,注意使用getChildFragmentManager,其它用法均一致
FragmentChild child = new FragmentChild();
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.discovery_container, child);
fragmentTransaction.commit();