Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling recyclerView with multiple view types causing strange overlapping of views #18

Open
techievbv opened this issue Mar 30, 2018 · 14 comments
Labels
migrated googlesamples Issue migrated from old repo location (googlesamples/)

Comments

@techievbv
Copy link

Hi,
The scenario I have is a recycler view containing items with different view types, i.e. i audio, video, image files all in a single adapter, in order to show media files as in other gallery apps.

Now, coming at the issue:
Whenever there are huge number of files present inside the recycler view, and I scroll through the items very fast (top-to-down and vice versa), some of the video thumbnails(of the video files) get overlapped over the audio files placeholder. Again, this happens only when the number of files is large and when scrolled quickly.

Just an FYI:
The getItemViewType() is returning the type of item in order to set appropriate views(for audio, video ,image).

Can anyone confirm if they have experienced a similar issue in the past ?
Or, any idea why this might be happening ?

@miquelcopet
Copy link

I'm having the same issue. Did you find any fix?

@miquelcopet
Copy link

miquelcopet commented Jul 18, 2018

Got it!
In onBindViewHolder you have to remove all the views from the container and then add the new view.

holder.viewGroup.removeAllViews();
holder.viewGroup.addView(view);

@Priyanshi-Z
Copy link

Hi,
Is there a way to solve this problem without removing All views and without doing setIsRecyclable set to false. Like a solution which doesn't decrease the performance of our recycler view.And Can you explain why this problem generally occurs @techievbv @mangini

@Priyanshi-Z
Copy link

@miquelcopet
The solution which you have suggested is just a hack.Not a solution.Is there a proper way which doesn't decrease the performance of recycler view.

@samkazmi
Copy link

I'm having the same issue. Anyone have a solution for this?

@Priyanshi-Z
Copy link

I'm having the same issue. Anyone have a solution for this?
Try this..
https://medium.com/@polson55/smooth-recyclerview-scrolling-in-android-57e7a9b71ca7

@codingjeremy codingjeremy transferred this issue from googlearchive/android-RecyclerView Sep 16, 2019
@codingjeremy codingjeremy added the migrated googlesamples Issue migrated from old repo location (googlesamples/) label Sep 16, 2019
@himanshu-infield
Copy link

any solution for this i am stuck in this problem and after adding holder.setIsRecyclable(false) my recyclyeview scroll lag

@asad175
Copy link

asad175 commented Nov 7, 2019

android:fitsSystemWindows="false" inside CoordinatorLayout will help. Here its explained how you can use a RecyclerView with Multiple View Types.

@BoumBam
Copy link

BoumBam commented May 24, 2021

I'm having the same issue. Anyone have a solution for this ?

@adarshsingh994
Copy link

The fix is simple!!

Let me explain, as you know recycler view recycles the views and does not create a new view unless needed. Since its recycling the previously created views its reusing the components inside it. So when the recycled view is reused, the layout is the same one to with it was binded before binding it with the new data. Now when you scroll normally the view gets replaced by the new view quickly and hence you do not notice it, but when you scroll fast the view is visible even before it gets binded. Got It?

Fix:
Just like there is an onBind method available in adapter class, there is an onviewRecycled method too. This method tells when the previous view is getting recycled to be used by a different value. Use this method to do a view cleanup

Example: If in onBind() you are setting an image in ImageView using Glide.with(context).load(uri).into(imageView) then in onViewCleared() you can call Glide.with(context).clear(imageView). This will clear the image view before onBind is called hence you won't see the previous image if you scroll fast.

Hope it helps :-)

@malookshah4
Copy link

I have same issue..

Im building chat layout like whatsap which has different views typs in recyclerview like video photos voice and msg views.
The problem is that when i scroll up and down some time the picture message view decreasing there size and some time voice msg decreasing there size and changing color..

Is there anyone to help me.

@Gaawk
Copy link

Gaawk commented May 30, 2023

Is this fixed for anyone? I'm building a chat app. Adapter works fine for me when in getItemViewType(), I return position but adding a new item to the list creates problem in this case. And if I return different two different viewTypes from getItemViewType(), adding new item works fine but list gets stuck in loop when i scroll. Anyone found any solution?

@malookshah4
Copy link

Is this fixed for anyone? I'm building a chat app. Adapter works fine for me when in getItemViewType(), I return position but adding a new item to the list creates problem in this case. And if I return different two different viewTypes from getItemViewType(), adding new item works fine but list gets stuck in loop when i scroll. Anyone found any solution?

use delegated Recyclerview adopter

@fast050
Copy link

fast050 commented Feb 16, 2024

Hi,
maybe your problem is that the layout :

  • is nested and you try to fill a lot of data in the XML.
  • using data binding and use custom data binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migrated googlesamples Issue migrated from old repo location (googlesamples/)
Projects
None yet
Development

No branches or pull requests