Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android fragment animation using compatibility package

How can I use animation for transitions between fragments ? I tried

FragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
FragmentTransaction.setCustomAnimations(android.R.anim.slide_in_left,
                                                 android.R.anim.slide_out_right);

changing the animation to different kind of animations, but it always seems to animate like fading-in while pushing fragment and fading out while popping fragment.

like image 807
pankajagarwal Avatar asked Jul 25 '11 06:07

pankajagarwal


1 Answers

I know this question is very old, but I stumbled upon it while looking for an answer to this myself.

I'm currently using animations in my compatibility package, fragment based app, and it's actually quite simple.

Add this before actually adding / replacing the fragments:

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

Your new fragment will slide in from the left on push, and slide out to the right on pop.

Of course this also works for other default animations, or custom animations.

like image 135
Sander van't Veer Avatar answered Nov 08 '22 01:11

Sander van't Veer