android Viewpager Only load one page one time

后端 未结 2 580
别跟我提以往
别跟我提以往 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: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 .

提交回复
热议问题