I'm trying to animate the transition between a pair of fragments using transaction.show
and transaction.hide
to swap fragments. I thought it would be simpler than using replace
as I understand this instantiates new fragments.
(The fragments would be reused possibly hundred+ of times, leading to high backstack memory usage, and managing the backstack would be a pain when I have a database saving all the fragment info anyway)
When I use
transaction.setCustomAnimations(R.animator.slide_out_right, R.animator.slide_in_left)
to animate the transition (or its reverse analog), the animation works but the fragment vanishes after the transition.
My transition animations are defined in XML as below - based in that given in this thread.
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="1280"
android:duration="500"
/>
</set>
- I am not using the support library.
- I am using one framelayout for both fragments, because I thought it would be simpler.
- The problem is similar in nature to that of this question, but there 2 framelayouts are used for each fragment, and the problem only occurs when 2 transitions occur within the 300ms animation time. The author found a workaround which is to use
AnimatorSet
on each Layout. As an android novice I'm not sure what (s)he means or how I would go about doing this.
Any idea where I'm going wrong? Is there another way to animate such a simple fragment transition as the person above seems to have done? Could it be a bug? Thank you.