Search code examples
androidandroid-recyclerviewandroid-glide

Android - Glide: How can I load images in order in a list?


I have a RecyclerView with some tiles and an ImageView to display some image from the network. To load the image I'm using Glide and the the good ol' loading method:

Glide.with(this)
        .load(url)
        .into(myImageView)

Despite being correctly loaded, images load in a random order. I can't figure out how to 'specify' the order of loading.

  • Is that even possible?
  • Is there any tweak in the RecyclerView I could make?
  • Does sb know about another library that supports this feature? Like Coil or Picasso.

Thanks in advance!


Solution

  • Despite being correctly loaded, images load in random order.

    From this statement my understanding is, all the images are correctly loading in respective ViewHolder but just the problem here is if there are 3 ViewHolders then you expect to load/display images from ViewHolder1, ViewHolder2, ViewHolder3 respectively but currently ViewHolder2 or ViewHolder3 might display image before ViewHolder1.

    If my above understanding is correct then I want to add few points here:

    1. The loading time of each image will be depending upon the various factor of the response image like its size, dimensions etc.
    2. Whenever you will scroll in the RecyclerView the ViewHolders will again get bind which will lead to make a request again for the same URL. To improve this you have to use the Glide caching mechanism so that the unnecessary fetching will be avoided.
    3. Regarding RecyclerView, you should try to implement it with DiffUtil, it is method by which the updates are more efficient.