У меня есть фрагмент, внутри которого есть еще один фрагмент, который является дочерним фрагментом, и он будет показан только в нижней половине экрана, тогда как родительский фрагмент - это полноэкранный вид.Я хочу заменить свой дочерний фрагмент другим дочерним фрагментом.Я следовал стандартному процессу замены фрагмента, но он показывает мне новый фрагмент поверх старого дочернего фрагмента.Я не уверен, что я делаю неправильно.Ниже мой 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();
}