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%" />
Jacek kwiecień
source share