Fragment hide animation does not play

I'm trying to switch my fragment with slide animation

Using this code:

FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); SearchPanelFragment existingFragment = (SearchPanelFragment) manager.findFragmentByTag(SearchPanelFragment.FRAGMENT_NAME); transaction.setCustomAnimations(R.xml.slide_down_search_panel, R.xml.slide_up_search_panel); if (existingFragment != null) { if (existingFragment.isVisible()) transaction.remove(existingFragment); } else { transaction.add(R.id.top_panel_fragment, new SearchPanelFragment(this), SearchPanelFragment.FRAGMENT_NAME); } transaction.commit(); 

So far, I only get input animation on transaction.add When is the output animation called? I could get it only when using transaction.replace , but then I just changed the old fragment with an identical new one, and I want to hide / delete / disconnect / everything that is necessary so that it disappears with the output animation playing

EDIT: I tried to hide, delete, and detach. No matter what I do, the animation does not play. It was played only when adding, showing and replacing

EDIT 2: Maybe something is wrong with the second animation. Please take a look at both of them. At first it slides down and seems to work fine.

Push down

 <translate android:duration="500" android:fromXDelta="0%" android:fromYDelta="-100%" android:toXDelta="0%" android:toYDelta="0%" /> 

Slide

 <translate android:duration="700" android:fromXDelta="0%" android:fromYDelta="0%" android:toXDelta="0%" android:toYDelta="-100%" /> 
+7
source share
2 answers

Edit

Bug fixed on June 7, 2013. I believe that since version 18 a bug has been fixed.

This should no longer be a problem if you are using the latest support library

Old answer

http://code.google.com/p/android/issues/detail?id=32405 There is an error in the support library. The only chance to get his job is to get the sources of the support library and recompile it yourself.

+8
source

In fact, you are using the wrong function.

According to the documentation for setCustomAnimations(int enter, int exit) :

Define specific animation resources to execute the fragments that enter and exit this transaction. These animations will not play when the back stack appears.

Instead, you should use setCustomAnimations (int enter, int exit, int popEnter, int popExit) :

Define specific animation resources to execute the fragments that enter and exit this transaction. The popEnter and popExit will play for input / output operations, especially when the back stack appears.

+9
source

All Articles