Change ViewPager animation duration when sliding programmatically

前端 未结 7 1128
清酒与你
清酒与你 2020-11-28 20:45

I\'m changing slide with the following code:

viewPager.setCurrentItem(index++, true);

But it changes too fast. Is there a way to set manual

7条回答
  •  难免孤独
    2020-11-28 20:59

    After wasting my whole day I found a solution set offscreenPageLimit to total no. of the page.

    In order to keep a constant length ViewPager scrolls smooth, setOffScreenLimit(page.length) will keep all the views in memory. However, this poses a problem for any animations that involves calling View.requestLayout function (e.g. any animation that involves making changes to the margin or bounds). It makes them really slow (as per Romain Guy) because the all of the views that's in memory will be invalidated as well. So I tried a few different ways to make things smooth but overriding requestLayout and other invalidate methods will cause many other problems.

    A good compromise is to dynamically modify the off screen limit so that most of the scrolls between pages will be very smooth while making sure that all of the in page animations smooth by removing the views when the user. This works really well when you only have 1 or 2 views that will have to make other views off memory.

    ***Use this when no any solution works because by setting offeset limit u will load all the fragments at the same time

提交回复
热议问题