android Viewpager Only load one page one time

后端 未结 2 564
别跟我提以往
别跟我提以往 2020-12-30 17:20

ViewPager.setOffscreenPageLimit(0) doesn't work as expected

Like the question. But I need a custom Viewpager which load one page on time. Is there any example?<

相关标签:
2条回答
  • 2020-12-30 17:31

    Depending on what you want to achieve (if it is just about saving memory or lowering loading time), you can also load all pages as usual but load the content of the fragment only when it actually gets displayed.

    0 讨论(0)
  • 2020-12-30 17:33

    Yes you can do this with following steps

    • First create a count variable in the adapter class
    • second in the ViewPager Adapter make a public function say setCount()
    • and in the override getCount() function of Adapter return the count variable
    • now override the on pageScroll() function of the ViewPager when the user flips the page you can call the setCount() to increase the count of the count variable
    • also check that if that the current index is last and page is scrolled to left

    this should work .

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