Recyclerview painfully slow to load cached images form Picasso

前端 未结 9 1230
夕颜
夕颜 2020-11-30 23:31

I have implemented a RecyclerView that contains mainly images which is loading in through Picasso. My problem is that as soon as I scroll down or up the view, the placeholde

9条回答
  •  粉色の甜心
    2020-12-01 00:14

    Picasso automatically cache images in two levels:

    • disk cache (this is actually NOT in picasso but in the network layer that picasso use)
    • memory cache

    They are bot initialized with defaults that suites most applications.

    When the memory cache is getting too big the oldest used bitmap is removed from memory cache (which by default is 1/7 of the available heap space).

    I think what's happening here is that you are close to the memory limit of the cache and thus images are decoded again every time you need them again.

    See here: Android Picasso Configure LruCache Size

    But I advice AGAINST increasing the memory cache size unless you really are re-sizing the images to the actual size you use..

    I think the problem with your code is this:

    .resize(deviceWidth, deviceWidth)
    

    are you sure you really need an image of that size? What do you store in PrefUtils ? does it get updated when the device rotate? (landscape vs portrait)

    If you need smaller images try to pass the resize the actual size of the image you are gonna use. If you don't know (computed at runtime with the layout) do with an approximation or write your code to obtain the actual size (I usually write custom classes extending ImageView for these stuff).

    If you really need the images at that size just increase the cache size (see link above) and you should be good to go.

提交回复
热议问题