androidfragment-transitions

How to show the fragment's enterTransition above the exitTransition


I want to show the enterTransition on top of the exitTransition.

But as you can see in the gif, the enterTransition is below the exitTransition.

How can I solve this problem?

The navigation component is used for fragment transitions.

enter image description here

EnterFragment.kt

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enterTransition = Slide().apply {
        duration = 2000
        slideEdge = Gravity.END
    }
}

ExitFragment.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    exitTransition = Slide().apply {
        duration= 3000
        slideEdge = Gravity.START
    }
}

nav_main.xml

<action
    android:id="@+id/move"
    app:destination="@id/fragment_enter"
/>

Solution

  • Please refer to the official documentation for transition animations with navigation component: https://developer.android.com/guide/navigation/navigation-animate-transitions

    You will need to put your animations in a respective animation xml file and then reference it in your nav_graph xml within the respective action. You can then specify when which animation should be used.