سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top