Change ViewPager2 Scroll Speed when sliding programmatically

前端 未结 2 1825
我寻月下人不归
我寻月下人不归 2021-02-19 04:10

I know there is way to change animation duration of ViewPager programmatical slide (here).

But its not working on ViewPager2

I tried t

2条回答
  •  滥情空心
    2021-02-19 04:55

    ViewPager2 team made it REALLY hard to change the scrolling speed. If you look at the method setCurrentItemInternal, they instantiate their own private ScrollToPosition(..) object. along with state management code, so this would be the method that you would have to somehow override.

    As a solution from here: https://issuetracker.google.com/issues/122656759, they say use (ViewPager2).fakeDragBy() which is super ugly.

    Not the best, just have to wait form them to give us an API to set duration or copy their ViewPager2 code and directly modify their LinearLayoutImpl class.

提交回复
热议问题