如何在 recyclerview 中使用 fresco 以获得最佳性能?

How to use fresco in recyclerview to gain best performance?

我有一个有很多图像的 recyclerview,我使用 fresco 加载图像。 但是当我将占位符用于图像时,我的 recyclerview 会变慢并滞后。 我在 XML 布局中为图像设置了一个占位符。我也在代码中尝试过,但我遇到了问题。 我在 xml 布局中使用了以下代码:

<com.facebook.drawee.view.SimpleDraweeView 
android:id = "@+id/my_image_view"
android:layout_width = "24dp"
android:layout_height = "24dp"
fresco:placeholderImage = "@drawable/my_placeholder" />

如何提高我的 recyclerview 性能?谢谢

Fresco 在此处有一个 RecyclerView 示例:https://github.com/facebook/fresco/blob/master/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/drawee/DraweeRecyclerViewFragment.java

如果您想试用 Showcase 应用程序,您可以克隆存储库并自行构建 Showcase 应用程序。 您的占位符是简单的 PNG 资产吗?占位符图像有多大,正常图像有多大?如果您尝试加载大图像,请确保为图像启用缩减采样/调整大小,请参阅 http://frescolib.org/docs/resizing.html

最好的方法是根据每个设备在drawable for placeholder 中创建hdpi、mdpi、xhdpi、xxhdpi 和xxxhdpi 资源文件夹,并在SimpleDraweeView 上使用fresco resizing 和downsampling。我这样做并获得了最佳性能而没有任何内存泄漏。