I'd like to force the animation triggered by the finger-swipe on a ViewPager - something like, when I press a button outside the ViewPager, it does the fancy animation. I've tried something like:

myPagerAdapter.instantiateItem(myPager, requested_view_id)
myPager.computeScroll()
myPager.invalidate()

But it didn't work.

Any ideas?

Thanks!

有帮助吗?

解决方案

If you just want to have a button or another event move to the "next page" or "previous page" in the ViewPager use ViewPager.setCurrentItem(int item). This will also show the animation. You will just need to keep track of the current item yourself and then setCurrentItem(numCurrentItem + 1).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top