How Can Make My Viewpager Load Only One Page at a Time Ie Setoffscreenpagelimit(0);

How to load only one page at time in view pager

you can't do that with a standard ViewPager implementation. If you see sources, you will see, that it sets offscreen page limit to 1, if it is less than 1.

public void setOffscreenPageLimit(int limit) {
if (limit < DEFAULT_OFFSCREEN_PAGES) { //DEFAULT_OFFSCREEN_PAGES if 1
Log.w(TAG, "Requested offscreen page limit " + limit + " too small; defaulting to " +
DEFAULT_OFFSCREEN_PAGES);
limit = DEFAULT_OFFSCREEN_PAGES;
}
if (limit != mOffscreenPageLimit) {
mOffscreenPageLimit = limit;
populate();
}
}

You can try to override this method in your custom class.

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

Does ViewPager require a minimum of 1 offscreen pages

Yes. If I am reading the source code correctly, you should be getting a warning about this in LogCat, something like:

Requested offscreen page limit 0 too small; defaulting to 1


Related Topics



Leave a reply



Submit