RecyclerView: Async image-loading

前端 未结 7 877
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 15:58

Im using RecyclerView to display a list containing an imageView. To make the UI more fluently, I load 58dp thumbnails saved on sd card into these i

7条回答
  •  余生分开走
    2020-12-28 16:35

    Due to view reuse you'll fetch views with content already on them, this was a problem on ListViews too if you were using the ViewHolder pattern, which you should.

    There are two solutions here, the good practice and the bad hack:

    • In the good practice you set your ImageView to display nothing at the beginning of bindViewHolder(VH holder, int position) using setDrawable(null) or similar.

    • In the bad hack you wouldn't recycle/reuse views, not enforcing the ViewHolder pattern, and you'd inflate it every time, but that's only allowed in ListView and other old components.

提交回复
热议问题