I need to use reverse() method of Android AnimatorSet class. The problem is that this method was added only in api 26. But I found reverse method in source code in package androidx.animation. And I couldn't find any androidx library that allows to use that AnimatorSet (androidx.animation.AnimatorSet). How can I use that class?
How to use androidx.animation.AnimatorSet?
294 Views Asked by Kiryl Tkach At
2
There are 2 best solutions below
2
On
For Api >=26 you just create an AnimatorSet object and after you define the animation you call reverse on it:
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(ObjectAnimator.ofFloat(...), ...);
animatorSet.setDuration(...);
animatorSet.reverse();
animatorSet.start();
For older APIs you just reverse the order within the .ofFloat methods in your ObjectAnimators:
If initially you have ObjectAnimator.ofFloat(0, 1) you change it to animator.setFloatValues(1, 0)
If you don't care it's still in alpha, you can import it from here: