我不知道我做错了什么。下面是包含父片段的xml文件。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.HomeActivity">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="56dp"
android:text="@string/title_mirror"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:itemIconTint="@drawable/bottom_nav_icon_color_selector"
app:itemTextColor="@drawable/bottom_nav_icon_color_selector"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
Below is my parent fragment xml file containing child fragment:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.smartmirror.emedsim.ui.mirror.DraggingPanel
android:id="@+id/outer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:id="@+id/queen_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:background="@color/transparent_black"
android:weightSum="3">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/up_arrow"/>
</LinearLayout>
<FrameLayout
android:id="@+id/frame_video"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</com.smartmirror.emedsim.ui.mirror.DraggingPanel>
</RelativeLayout>
下面是我从父片段添加子片段的文件:
private void initViews(View view) {
mDraggingPanel = view.findViewById(R.id.outer_layout);
mMainLayout = view.findViewById(R.id.main_layout);
Fragment childFragment = new DiscoveryFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.replace(R.id.frame_video, childFragment).commit();
}
上面的第一个子片段添加成功。
private void proceedFurther(int position, View v) {
FragmentManager fragmentManager = ((AppCompatActivity) mContext).getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
Fragment childFragment = new VideoIntroScreen();
childFragment.setArguments(args);
transaction.replace(R.id.frame_video, childFragment);
transaction.commit();
}