Skip to content Skip to sidebar Skip to footer

Images Disappear When Scrolling Up And Down And Spaces Increase Between Images Using Glide And Recyclerview

I have a RecyclerView to display my images and I use Glide to load images from their URLs from my database in Firebase Storage. The problem is, when I scroll up and down, images re

Solution 1:

I think the problem lies in the way you add the item into the list.

try to change it to

adapter = newImageRecyclerAdapter(MainActivity.this,list);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(newLinearLayoutManager(MainActivity.this));

for(int i=0;i<imageNames.size();i++) {
    StorageReferenceref= storageReference.child("filee/" + imageNames.get(i));
    ref.getDownloadUrl().addOnSuccessListener(newOnSuccessListener<Uri>() {
        @OverridepublicvoidonSuccess(Uri uri) {
            StringimageURL= uri.toString();
            ImageClassimageClass=newImageClass();
            imageClass.setName(imageURL);
            list.add(imageClass);
            adapter.notifyDataSetChanged();
            Toast.makeText(MainActivity.this, "Downloaded", Toast.LENGTH_SHORT).show();
        }
    }).addOnFailureListener(newOnFailureListener() {
        @OverridepublicvoidonFailure(@NonNull Exception exception) {
            Toast.makeText(MainActivity.this, "Not Downloaded", Toast.LENGTH_SHORT).show();
        }
    });

}

and is the getDownloadUrl() returns the result in the sequence they are called? If no, then it is likely that images loads with random sequence on the list.

Solution 2:

For some unknown reason, setting the image view's visibility to VISIBLE solved the problem for me. As in, after loading with Glide, write, holder.imageView.visibility = View.VISIBLE

Post a Comment for "Images Disappear When Scrolling Up And Down And Spaces Increase Between Images Using Glide And Recyclerview"