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%" />
Edit
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
Old Answer
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