How to animate item update when using ViewPager2 with RecyclerView.Adapter?

648 Views Asked by At

I need to animate a particular item update. In RecyclerView we can use ItemAnimator for such animation. What can we use for ViewPager2?

1

There are 1 best solutions below

2
On

You would use a ViewPager2.PageTransformer, to animate the Fragments when they are swapped between.

Here is a link containing some cool animation. Due note these are for ViewPager not ViewPager2, so you will have to modify them a bit. Luckily the interface has same signatures so it should be straight forward.

I've personally used two of them and they work great.

The only thing you will have to look out for is depth based animations TranslationZ those require API 21, if that's an issue for you.

https://www.loginworks.com/blogs/how-to-make-awesome-transition-effects-using-pagetransformer-in-android/