Royi Journo
Royi Journo

Reputation: 37

android.R.anim.fade_out Doesn't work well, just fade in work

I want to switch between fragment with animation. Current, I use this:

FragmentTransaction fr = getFragmentManager().beginTransaction();
//fr.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
fr.setCustomAnimations(android.R.anim.fade_in,android.R.anim.fade_out);
fr.replace(R.id.fragment_container,new SwimSuitFragment());
fr.addToBackStack(null);
fr.commit();

the fade_in work well, but when I press back it goes straight to the previous fragment, and don't do the fade out animation.

Upvotes: 1

Views: 183

Answers (1)

Beyazid
Beyazid

Reputation: 1835

From official document;

The popEnter and popExit animations will be played for enter/exit operations specifically when popping the back stack.

public abstract FragmentTransaction setCustomAnimations (int enter, 
                int exit, 
                int popEnter, 
                int popExit)

You should use this instead of your setCustomAnimations

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

Upvotes: 1

Related Questions