简体   繁体   中英

How to make PagerAdapter load all pages


I know that by default PagerAdapter loads only the current, next and previous pages. Is there any way to change it, so it will load each and every page? Thanks!

如果您有N页面,则可以使用setOffscreenPageLimit(N-1) ,以便将所有页面保留在内存中。

I'm not sure this is an answer, but the whole concept of an adapter (also for lists/grids, etc) is that you don't have all the Views loaded to the memory all the time, but it inflates only what's visible. Think about a ListView with 10000 items, the app would crash if it would try to load them all.

The documentation states somewhere that "setOffscreenPageLimit" can be useful and faster if you know how many pages and content you want to show. If you know the information to be shown and it is not heavy weight "setOffscreenPageLimit" would actually improve your performance because the views are only inflated once.

I'm not sure this is an answer, but the whole concept of an adapter (also for lists/grids, etc) is that you don't have all the Views loaded to the memory all the time, but it inflates only what's visible.

Think about a ListView with 10000 items, the app would crash if it would try to load them all.

With HorizontalScrollView you'll have all the views loaded to memory.

我认为不可能一次加载所有页面。您应该重新设计代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM