androidkotlinandroid-fragmentsfragmentmanager

Problem replacing Fragment within another one. (fragments overlapping)


I try go to SaveRouteFragment from RecordRouteFragment. The result is that both fragments are overlapping on each other. I was searching Internet and didn't find an anwer to my issue, although some people had similar issues with overlapping.

Overlapping fragments

fragment_record_route.xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".features.routerecording.ui.RecordRouteFragment">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/cl_frg_container">

        // content

    </FrameLayout>
</LinearLayout>

fragment_save_route.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

        // content

</androidx.constraintlayout.widget.ConstraintLayout>

onClickListener from RecordRouteFragment.kt

private val btStopRecordOnClick = View.OnClickListener()  {
        stopLocationService()
        viewModel.markRouteAsNotCurrent()

        childFragmentManager.commit {
            replace<SaveRouteFragment>(binding.clFrgContainer.id) //when I replace that with usual R.id.cl_frg_container - nothing changes
            setReorderingAllowed(true)
            addToBackStack("Save a route") // name can be null
        }
    }

What I am doing wrong?


Solution

  • I had to change background color of SaveRouteFragment to e.g. white.