I'm having trouble using or understanding how FragmentTransactions from the back stack handles custom animations. In particular, I expect it to trigger an “outside” animation, but that doesn't look like it.
I have a simple fragment transaction processing method (FragmentTransaction), where I add a fragment and apply a transition so that it disappears / disappears. I also add this to the back so that the user can cancel this transaction using the back, essentially going to the state before the fragment was added.
protected void changeFragment() { FragmentTransaction ft = fm.beginTransaction(); ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); ft.add(R.id.fragment_container, new TestFragment()); ft.addToBackStack(null); ft.commit(); }
Everything works fine, but when the user presses the back button, the transition animation does not change. What I expected was that when the fragment was deleted, it would use the fading animation. Instead, it seems to pop up (without animation), and then the container seems to disappear. I'm not sure that this is exactly what is happening, but the fragment definitely does not disappear.
My application uses a compatibility library to add fragment support, but I assume this applies to Honeycomb (android-11). Does anyone know if I'm just doing something wrong here, or if I'm just expecting too much? Ideally, I would like to animate fragments in the same way that Gmail (on Xoom) does in relation to moving forward by clicking a message and then back using the back button. It is preferable not to have to redefine the back button of the functionality and keep up with my own state of fragments, as I could have several “transactions” that I would like to backtrack, and I'm not a fan of reinventing the wheels.
Also asked in the Android development group: http://groups.google.com/group/android-developers/browse_thread/thread/1136a3a70fa0b6e9
android animation android-fragments transactions transitions
Kelly Merrell Mar 16 '11 at 15:31 2011-03-16 15:31
source share