我有自定义列表视图。在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));
}
}
如果我做错了,请弄清楚。谢谢你的进步。