简体   繁体   English

Recyclerview NetworkImageView(凌空)没有显示出来

[英]Recyclerview NetworkImageView (volley) doesn't show up

I am using RecyclerView and volley's NetworkImageView to render images once they are downloaded. 我使用RecyclerView和volley的NetworkImageView在下载后渲染图像。 The view consists of an author image, some text fields and a picture. 视图由作者图像,一些文本字段和图片组成。 Following is the code snippet to populate the view: 以下是填充视图的代码段:

// vh is the viewholder    
vh.picture.setDefaultImageResId(R.drawable.default_image);
vh.picture.setImageUrl(post.getImageUrl(), mImageLoader);

The problem I am facing is when scrolling, out of say 20 images, mostly ~18 show up. 我面临的问题是滚动时,说出20张图像,大多数是〜18出现。 I see from the logs that all images are downloaded and are in the cache, but some are not rendered. 我从日志中看到所有图像都已下载并位于缓存中,但有些图像未呈现。 Even the default image is not displayed for those views. 甚至不会为这些视图显示默认图像。 If the view is invalidated (scroll up and down again), the images show up. 如果视图无效(再次向上和向下滚动),则会显示图像。

Funny thing is, for the views where the picture is not displayed, even the author pic is not displayed, even if I can see the same author pic in a post just above it. 有趣的是,对于没有显示图片的视图,即使我可以在其上方的帖子中看到同一作者图片,也不会显示作者图片。 Its as if the entire view has a problem displaying images. 就像整个视图显示图像一样有问题。

Is there any way to call invalidate() or postInvalidate() on NetworkImageView manually once the images are downloaded? 下载图像后,有没有办法在NetworkImageView手动调用invalidate()postInvalidate() Or any other ideas? 还是其他任何想法?

This was also asked here . 这也是在这里问的。 I finally got around to this problem by not using NetworkImageView at all. 我终于通过不使用NetworkImageView解决了这个问题。 I started using the regualar ImageView, am still fetching the images through volley through a custom image request and onResponse() applying the image on the view. 我开始使用regualar ImageView,仍然通过自定义图像请求和onResponse()应用图像在视图上获取图像。 This seems to work pretty well. 这看起来效果很好。

    public void getImage(String url, final ImageView v) {
    if (TextUtils.isEmpty(url)) return; // don't fetch a null url

    ImageRequest imageRequest = new ImageRequest(url, new Response.Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            v.setImageBitmap(response);
        }
    }, 0, 0, null, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Error- " + error.getMessage());
        }
    });

    mRequestQueue.addToRequestQueue(imageRequest);
}

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

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