I've seen lots of people describing this happening with child fragments (for example), but I'm not using child fragments. When I add animations to the transaction, the exiting fragment disappears instantly while the entering fragment enters with the expected enter animation. When I press back, the same thing happens...the exiting fragment disappears instantly and the original fragment enters with the appropriate pop enter animation.
What have I done wrong?
I'm doing this in an AppCompatActivity
that implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback
, and my layout for the activity consists solely of a FrameLayout.
override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference): Boolean {
val fragment = supportFragmentManager.fragmentFactory.instantiate(
classLoader,
pref.fragment)
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right)
.add(R.id.fragment_wrapper, fragment)
.addToBackStack(null)
.commit()
return true
}
All of my animations are simple translate anims with the same duration, like this:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXDelta="100%p" android:toXDelta="0"
android:duration="@integer/fragment_transition_time"/>
I'm using androidx.preference:1.1.0-alpha05
.