简体   繁体   English

壁画:在列表项中显示错误的图像

[英]Fresco : Display Wrong Image in listitems

I am using fersco library for loading local image. 我正在使用fersco库加载本地图像。 Initially i am displaying placeholder image in each item.Once the image is downloaded then i am storing that image in to local path and then load image via setImageUri function. 最初我在每个项目中显示占位符图像。一旦下载了图像,则将其存储到本地路径中,然后通过setImageUri函数加载图像。 If i am scrolling fast at the time of downloading image it display different image and re-appearing some time keep on changing if i am stop scrolling. 如果我在下载图像时快速滚动,它将显示不同的图像并重新出现一些时间,如果我停止滚动,则继续更改。

My SimpleDraweeView : 我的SimpleDraweeView:

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/fake_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
           android:layout_gravity="center|center_horizontal|center_vertical"
            android:adjustViewBounds="true"
            android:contentDescription="@string/app_name"
            android:scaleType="centerInside" /> 

My Adapter Code is : 我的适配器代码是:

GenericDraweeHierarchy hierarchy = setHierarchyForDraweeView(mImageView, 300);

hierarchy.setFailureImage(mContext.getResources().getDrawable(R.drawable.broken_image_black)); 层次结构.setFailureImage(mContext.getResources()。getDrawable(R.drawable.broken_image_black)); mSimpleDraweeView.setImageURI(Uri.fromFile(new File(mPath/ local path /))); mSimpleDraweeView.setImageURI(Uri.fromFile(new File(mPath / local path /)));

SetHierarchyForDraweeView Function : 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 Class : AsyncColorDrawable类:

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

I am doing anything wrong ? 我做错了什么?

I see several things that should be fixed, but none of which would explain incorrect loading. 我看到一些应该修复的问题,但是没有什么可以解释不正确的加载。 I will be able to help, but I'll need the logcat logs as explained here . 我将能够提供帮助,但是我需要这里介绍的logcat日志。 Also, there is one thing I don't fully understand. 另外,有一件事我还不完全了解。 From your description it seems that you are downloading your images manually, saving them to disk and when they are downloaded you set the Uri. 从您的描述看来,您似乎是在手动下载图像,并将其保存到磁盘,并且在下载图像时,您设置了Uri。 Why not using Fresco to automatically download and disk-cache images for you? 为什么不使用Fresco为您自动下载和磁盘缓存图像? Can you provide this piece of code as well, because the issue might very well be there. 您是否也可以提供这段代码,因为问题很可能就在那里。

Things that should be fixed: 应该解决的问题:

  1. adjustViewBounds and scaleType attributtes are not supported by SimpleDraweeView . SimpleDraweeView不支持adjustViewBoundsscaleType属性。 Drawee operates on several images at once (placeholder, failure image, actual image, etc.) Each can have its own scale type so you need to use Drawee atrributes as explained here . 付款人在几个图像一次(占位符,失败的图像,实际图像等),所以你需要为解释使用付款人atrributes每个人都可以有自己的规模型经营这里

  2. If you are inflating your view from XML, draweeView.getHierarchy should never be null. 如果要从XML draweeView.getHierarchy视图,则draweeView.getHierarchy永远不应为null。 You would have a NullPointerException anyway because you are not returning hierarchy from that if-branch. 无论如何,您将有一个NullPointerException,因为您没有从该if分支返回层次结构。 So, you can specify your failure image via XML too, no need to do that programmatically. 因此,您也可以通过XML指定故障图像,而无需以编程方式进行操作。 Same for the fade duration if you always use the same value. 如果始终使用相同的值,则淡入时间相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM