If you added or removed multiple fragments within a single transaction, all of those operations are undone when the back stack is popped. The optional name provided in the addToBackStack() call gives you the ability to pop back to that specific transaction using popBackStack() .
To animate the transition between fragments, or to animate the process of showing or hiding a fragment you use the Fragment Manager to create a Fragment Transaction . Within each Fragment Transaction you can specify in and out animations that will be used for show and hide respectively (or both when replace is used).
At a high level, here's how to make a fragment transition with shared elements: Assign a unique transition name to each shared element view. Add shared element views and transition names to the FragmentTransaction . Set a shared element transition animation.
The enterAnim and exitAnim is applied when navigating to or from the destination the "regular way", while popEnterAnim is applied to the destination when it is shown as a result of the destination "above" it being popped from the backstack.
I use this:
ft.setCustomAnimations(R.anim.slide_in, R.anim.hyperspace_out, R.anim.hyperspace_in, R.anim.slide_out);
and the transitions work in reverse when the back button is presses.
The bug was fixed in the 3.2 release with the addition of the following new api:
http://developer.android.com/reference/android/app/FragmentTransaction.html#setCustomAnimations(int, int, int, int)
It's to be noted that it has not yet been back-ported to the compatibility library (as mentioned in the bug report).
It's a bug, look at bug report 15623. One of the Android project members commented that the fix was too late for release 3.1 but it should make it into the next release.
The same member goes on to say that...
The problem is that the same animations are run on a pop operation as were run to put the fragments in their current places. For example, in the sliding example above, on a forward operation (pushing the old fragment onto the stack and moving the new fragment into view), we slide the old fragment out from the center to the left and slide the new fragment in from the right to the center. When the stack is popped, these same animations are run: the most recent fragment is animated 'out' by sliding it in from the right to the center (after which it disappears, since it's being removed). The old fragment is popped off the stack and animated from teh center to the left ... right off the screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With