I have a listing of some item and I am using Glide
to load an image onto an ImageView. The problem is, if a particular item, scroll-enter the screen, that is the only time I saw image is being drawn using Glide
. This is noticeable when I put crossfade when the image has finished loading.
I know from the start the number of items needed and couple of other items like header and footer. I am thinking of just making a very long view to handle everything and dynamically add those known items at onCreate
and just use ScrollView
which I have done. I currently implemented a simpler way using a RecyclerView
but I having trouble regarding the timing of onBindView
call.
What I want is to load first 5 items before they become visible into the screen. This I hope will trigger the method where I bind the image onto the ImageView with Glide before it is fully visible into the screen.
I followed this tutorial and its not working for me. Here is my current setup:
mComicListingAdapter = new ComicListingsAdapter(getContext(), Constants.CHAPTERS, (ComicListingsAdapter.Callback) getActivity());
mRecycleViewHomeScreen.setAdapter(mComicListingAdapter);
mRecycleViewHomeScreen.setHasFixedSize(true);
mRecycleViewHomeScreen.setItemViewCacheSize(42);
mRecycleViewHomeScreen.setLayoutManager(pcll);
Is this possible in RecyclerView? Or maybe I should try dynamically creating ImageView
and appending them to a parent View
as I have done so. It looks great but there is a lot of things to do in my case using this method. I am just curious if I can direct RecyclerView
to load n-amount of items in advance.
Thanks!
I've found a blog post where author suggest to extend LinearLayoutManager and override getExtraLayoutSpace().
And it worked. More items were preloaded depending on the number of pixels returned in getExtraLayoutSpace().
P.S. I've not checked yet how that affects performance, especially on pre-lollipop devices.
Sample:
val customLayoutManager = CustomLayoutManager(this)
recyclerView = findViewById<RecyclerView>(R.id.recyclerView).apply {
layoutManager = customLayoutManager
... //
}
class CustomLayoutManager(context: Context?) : LinearLayoutManager(context) {
override fun getExtraLayoutSpace(state: RecyclerView.State?) = 2000
}
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