RecyclerView laggy scrolling

后端 未结 13 736
闹比i
闹比i 2020-12-09 09:44

I am loading 400x200 images in RecyclerView, but scrolling is laggy on 2k devices. I am using Picasso for loading images from resource.

As you can see in the demo ima

相关标签:
13条回答
  • 2020-12-09 10:23

    from my experience with recyclerview what i found the possible cause could be is the image size. beside that adding property ( setNestedScrollingEnabled(false); ) to the recyclerview and ( setHasStableIds) to the adapter does help to make recyclerview work smoothly. So, bottom line is, if your recyclerview has image to load from network make sure to override their size or use thumbnail property(in glide). this tricked saved my life and i hope it might save others life as well. Happy coding :)

    0 讨论(0)
  • 2020-12-09 10:24

    Is RecyclerView.setHasFixedSize() set to true? I'm not able to reproduce this lag...can you please post the whole project on git? Check this out, maybe it can help you: http://antonioleiva.com/recyclerview/

    0 讨论(0)
  • 2020-12-09 10:24

    This is because the image is taking time to load. Firstly, change your code for loading image as the below one...

    Picasso.get().load(list.get(position).id).fit().centerCrop()
                    .placeholder(R.drawable.ic_launcher)
                    .into(holder.cardimage);
    

    Then, before setting the adapter on recyclerview to the instance of CardAdapter inside MainActivity add this line..

            yourAdapter_name.setHasStableIds(true);
    

    One more tip...If anyone is using large drawables (xxxhdpi, xxhdpi ), first convert them into mdpi or ldpi . This will also improve the performance a lot and also reduces the apk size.You can use this website NativeScript Image Builder

    0 讨论(0)
  • 2020-12-09 10:32

    You need to be getting the images asynchronously. As it is now, it stalls to actually download the image.

    Leave the imageview blank when it's created, but have some sort of listener to set the image when it's been downloaded.

    0 讨论(0)
  • 2020-12-09 10:33

    if you are using two or more recycler views like (RecyclerView and NestedView) try this

    recyclerView.setNestedScrollingEnabled(false);
    

    Source : Recyclerview inside Nested Scrollview scroll but does not fast scroll like normal Recyclerview or Nested Scrollview

    0 讨论(0)
  • 2020-12-09 10:35

    I Believe that sometimes you may piss off when only trying some static images in drawable to display your recycler view. And it happens extremely lagging.

    Why? You may not get this issue when using some library to load an image from url (Picasso, Glide, ...), but what happens with the same image, the same size, and it's right in your drawable (not need to download at all). And after a while, I figure out, android did some trick to resize an image in drawable for us to get a proper image in different resolution devices. So my suggestion is to use drawable-nodpi to store your image in order for android not to interfere with our images.

    0 讨论(0)
提交回复
热议问题