I'm trying to improve the user experience while scrolling a grid of images by prefetching views ahead of time using the new API introduced in the support library 25.1 for controlling the number of prefetched items in a RecycleView.
GridLayoutManager layoutManager = new GridLayoutManager(this.getContext(), PhotoGridViewHolder.SPAN_SIZE);
layoutManager.setItemPrefetchEnabled(true);
layoutManager.setInitialPrefetchItemCount(30);
photosRecycleView.setLayoutManager(layoutManager);
... add 100 photos to the adapter ...
And I also added logging for my ViewHolders so I could see if the binding really happened.
void bind(final Photo photo, int position) {
// I expcet to see 30 logs without event scrolling as the intial set to 30.
log.d("binding photo: " + photo.getId());
loadPhoto(photo);
}
However, it seems like it's not working, as I loaded a list of 100 images but I see only a few log entries (just fetching the visible items), but I'd expect to see at 30 as I set it to be like so.