Android Fragment Animation Using Compatibility Pack

How can I use animation to transition 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 types of animations, but it always seems lively, like fading when you click on a fragment and fade when a fragment appears.

+6
source share
1 answer

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

I am currently using animation in my fragment-based compatibility pack, and it's actually quite simple.

Add this before the actual add / replace 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 move to the left of the click and slip to the right by clicking.

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

+11
source

Source: https://habr.com/ru/post/893477/


All Articles