set ViewPager current item with animation

863 views Asked by At

I have a viewpager and I have used a simple page transformer. The animation works on swiping the viewpager but it does not work when i call

mViewPager.setCurrentItem(position);

the page changes but without any animation. How do I apply the animation to the viewpager even when the page item is changed by clicking the next/previous button

1

There are 1 answers

5
The Badak On

there's a smoothScroll parameter in setCurrentItem method if you check the documentation

try replacing

mViewPager.setCurrentItem(position);

with

mViewPager.setCurrentItem(position, true);

(i haven't checked if it is working, but it might work)