I'm using the new Viewpager2 with a recycler view to show a list of pages. To create a stack like view I'm using ViewPager2.PageTransformer
I've noticed that according to the documentation for the ViewPager2.setPageTransformer()
it stats the following
Note: setting a ViewPager2.PageTransformer disables data-set change animations to prevent conflicts between the two animation systems. Setting a null transformer will restore data-set change animations.
So after adding the page transformer I animation for page removing and page adding is no more working
Is there any way to overcome this
Below is the implemented code
Page Transformer
public class VerticalStackViewPageTransformer implements ViewPager2.PageTransformer {
int pageTranslationY ;
public VerticalStackViewPageTransformer(int pageTranslationY) {
this.pageTranslationY = pageTranslationY;
}
@Override
public void transformPage(@NonNull View page, float position) {
page.setTranslationY(-pageTranslationY * position);
page.setScaleX(1 - (0.15f * abs(position)));
page.setAlpha(0.65f + (1 - abs(position)));
}
}
Usage On Activity
listViewPager.setAdapter(adapter);
listViewPager.setOffscreenPageLimit(2);
listViewPager.setPageTransformer(new VerticalStackViewPageTransformer(ContextHelper.dpToPixel(30,context)));