I'm trying to toggle 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 get only enter animation on transaction.add
When is exit animation played? I could only get it when using transaction.replace
but then I was just swaping an old fragment with identical new one, and what I want is to hide/remove/detach/whatever it's neccessary to make it dissapear with exit animation played
EDIT: I tried hide, remove and detach. No matter what I do, the animation is not played. It's played only on add, show, and replace
EDIT 2: There might be something wrong with the second animation. Please take a look on both on them. First one slides down and seems to be working just fine.
Slide down
<translate
android:duration="500"
android:fromXDelta="0%"
android:fromYDelta="-100%"
android:toXDelta="0%"
android:toYDelta="0%" />
Slide up
<translate
android:duration="700"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="-100%" />
You're actually using the wrong function.
According to the documentation for setCustomAnimations(int enter, int exit)
:
Set specific animation resources to run for the fragments that are entering and exiting in this transaction. These animations will not be played when popping the back stack.
Instead you should use setCustomAnimations (int enter, int exit, int popEnter, int popExit)
:
Set specific animation resources to run for the fragments that are entering and exiting in this transaction. The
popEnter
andpopExit
animations will be played for enter/exit operations specifically when popping the back stack.
The bug has been fixed as of June 7th 2013. I believe starting at revision 18, the bug has been fixed.
This no longer should be an issue if you are using the latest Support Library Revision
http://code.google.com/p/android/issues/detail?id=32405 There is a bug in support library. The only chance to get it work is get support library sources and recompile it yourself
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