gpt4 book ai didi

android - Fresco : Listview showing wrong image when fast scrolling

转载 作者:行者123 更新时间:2023-11-29 14:13:44 24 4
gpt4 key购买 nike

我有自定义 ListView 。在 ListView 中包含 200 个项目。当我从上到下或从下到上快速滚动 ListView 时显示错误的图像。如果我滚动缓慢,那么它的工作正常。

XML 中的 SimpleDraweeView:

<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/fake_image_list_group"
android:layout_width="match_parent"
android:layout_height="@dimen/note_list_item_height"
android:background="@android:color/transparent"
android:contentDescription="@string/app_name" />

将图片 URI 设置为 SimpleDraweeView :

GenericDraweeHierarchy hierarchy = setHierarchyForDraweeView(mImageView, 300);
hierarchy.setPlaceholderImage(new AsyncColorDrawable(context.getResources()));
hierarchy.setFailureImage(mContext.getResources().getDrawable(R.drawable.broken_image_black));
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(mPath/*local path*/)))
.setResizeOptions(new ResizeOptions(width, height))
.setLocalThumbnailPreviewsEnabled(true)
.build();
DraweeController draweeController = Fresco.newDraweeControllerBuilder()
.setImageRequest(imageRequest)
.setOldController(mImageView.getController())
.setAutoPlayAnimations(false)
.build();
mImageView.setController(draweeController);

SetHierarchyForDraweeView 函数:

private GenericDraweeHierarchy setHierarchyForDraweeView(SimpleDraweeView draweeView, int duration) {
if (draweeView != null) {
if (draweeView.getHierarchy() == null) {
GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(mContext.getResources());
GenericDraweeHierarchy hierarchy = builder
.setFadeDuration(duration)
.setPlaceholderImage(new AsyncColorDrawable(mContext.getResources()))
.setFailureImage(mContext.getResources().getDrawable(R.drawable.broken_image_black))
.build();
draweeView.setHierarchy(hierarchy);
} else {
GenericDraweeHierarchy hierarchy = draweeView.getHierarchy();
hierarchy.setFadeDuration(duration);
return hierarchy;
}
}
return null;
}

AsyncColorDrawable 类:

private class AsyncColorDrawable extends ColorDrawable {
public AsyncColorDrawable(Resources res) {
super(res.getColor(R.color.application_container_background_color));
}
}

如果我做错了什么,请找出来。感谢您的提前。

最佳答案

为此,您需要使用 Universal Image Loader。它是一个智能且功能强大的库,有助于在 Android 上加载、缓存和显示图像。看看this

关于android - Fresco : Listview showing wrong image when fast scrolling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35770109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com