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.
LayoutManager implementations that lays out items in a grid. WearableLinearLayoutManager. This wear-specific implementation of LinearLayoutManager provides basic offsetting logic for updating child layout. A RecyclerView. LayoutManager implementation which provides similar functionality to ListView .
In this tutorial you will learn step by step how to create a nested recyclerview. This is whereby you are placing a recyclerview within another recyclerview. Each recyclerview needs to have it's independent adapter to bind it's data.
As @FlanschiFox and comments below his answer says, this is only working for inner RecyclerViews. Additionally, I wrote a PreloadLinearLayoutManager
here to preload data 5 items before the list scrolls to the end. It may help you a bit.
According to the docs, this is only working for inner RecyclerViews.
Documentation: isItemPrefetchEnabled
Sets the number of items to prefetch in collectInitialPrefetchPositions(int, LayoutPrefetchRegistry), which defines how many inner items should be prefetched when this LayoutManager's RecyclerView is nested inside another RecyclerView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With