android / views-widgets-samples

Multiple samples showing the best practices in views-widgets on Android.
Apache License 2.0
5.05k stars 3.01k forks source link

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

Open techievbv opened 6 years ago

techievbv commented 6 years ago

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 commented 6 years ago

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

miquelcopet commented 6 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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

Priyanshi-Z commented 5 years ago

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

himanshu-infield commented 4 years ago

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

asad175 commented 4 years ago

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

BoumBam commented 3 years ago

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

adarshsingh994 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 11 months ago

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 commented 7 months ago

Hi, maybe your problem is that the layout :