Support library: FragmentTransaction animations not working

Adil Hussain picture Adil Hussain · Jan 26, 2012 · Viewed 12.2k times · Source

I'm using Peter Doyle's android-support-v4-googlemaps support library for implementing an Activity that uses both Fragments and Google Maps, and can't seem to get FragmentTransaction animations to work. I've tried using the setCustomAnimations(int enter, int exit) method as well as the setTransition(int transit) method but to no avail. Anyone been able to get animations to work, or also had problems getting animations to work?

Some of the animations I tried:

setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)

setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)

setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right)

Answer

VSB picture VSB · Sep 22, 2013

You should call FragmentTransaction.setCustomAnimations first and then call FragmentTransaction.replace method like this:

        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.anim.fade_out,R.anim.fade_in);
        ft.replace(R.id.fragmentDetails, detailsFrag);