3

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"
/>
dylan.kwon
  • 435
  • 5
  • 14
  • What happen if you use same duration for both . i think that will a slide translation . Isn't it what you want ? – ADM Mar 27 '21 at 06:06
  • Thank you for answer. The gif is just an example, and ultimately the animation I want is not a slide. In order to do that, the enterTransition must be visible above the exitTransition. – dylan.kwon Mar 27 '21 at 06:11

1 Answers1

2

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.

J. Hegg
  • 1,365
  • 11
  • 31
  • 1
    While that may work, that doesn't solve the issue of how we can achieve this using `setEnter`/`setExitTransition` on Fragments. In my case, I want to define the animations at runtime and want them to be dynamic, so the static xml approach does not work for me. It's odd that the the Android documentation "strongly recommends to use the transition framework": https://developer.android.com/guide/fragments/animate. Yet the jetpack library, and most solutions online still use `setCustomAnimations`. – sbearben Jul 22 '21 at 21:48