Замена childFragment другим childFragment помещает вид сверху - PullRequest
0 голосов
/ 12 декабря 2018

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

Ответы [ 2 ]

0 голосов
/ 12 декабря 2018

Вы должны убедиться, что используете правильный FragmentManager.В вашем методе initViews() вы используете дочерний элемент FragmentManager родительского элемента Fragment. In the continueFuture () method, you're using the Activity FragmentManager` (который содержит родительский фрагмент).

Итак, у вас есть:

Activity
  -> Parent Fragment (in Activity FragmentManager)
     -> Child Fragment 1 (in Parent Fragment Child FragmentManager)

Чтобы правильно заменить «Дочерний фрагмент 1», вам нужно использовать дочерний элемент FragmentManager из «Родительского фрагмента».

0 голосов
/ 12 декабря 2018

Мне удалось получить решение для моего ответа.Я отвечаю, если кому-то это нужно.

Я просто добавил ? Android: windowBackground в мои файлы макетов фрагментов и решил проблему с перекрытием моего вида.

Добавьте это вмакет корневого макета вашего родительского и дочернего фрагмента.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...