How does setOffscreenPageLimit() improve ViewPager performance by retaining more offscreen Fragments?

后端 未结 1 1114
太阳男子
太阳男子 2021-02-08 19:39

I have a ViewPager controlling five Fragments. When I swipe from Fragment at index 1 to Fragment at index 0, there\'

1条回答
  •  情话喂你
    2021-02-08 20:14

    When you use the default implementation of setOffscreenPageLimit() it is only loading the one fragment which is to the right of it. For eg. when you are on index 1, it has index 2 loaded in memory but not index 0, so swiping left will have to generate a new fragment from scratch. To test this theory you might want to use setOffscreenPageLimit(2) and then try swiping index 1->0. This in no way is the optimal solution but will help clear out your doubts about the concept.

    0 讨论(0)
提交回复
热议问题