Recyclerview NetworkImageView(排球)未显示 [英] Recyclerview NetworkImageView (volley) doesn't show up

查看:105
本文介绍了Recyclerview NetworkImageView(排球)未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下载图像后,我正在使用RecyclerView和凌空的NetworkImageView渲染图像.该视图由作者图像,一些文本字段和图片组成.以下是填充视图的代码段:

I am using RecyclerView and volley's NetworkImageView to render images once they are downloaded. 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);

我面临的问题是在滚动时(显示20张图像,大部分显示〜18张图像).我从日志中看到,所有图像均已下载并且位于缓存中,但有些未渲染.这些视图甚至都不会显示默认图像.如果视图无效(上下滚动),则会显示图像.

The problem I am facing is when scrolling, out of say 20 images, mostly ~18 show up. 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.

下载图像后,是否可以通过手动方式在NetworkImageView上调用invalidate()postInvalidate()?还是其他想法?

Is there any way to call invalidate() or postInvalidate() on NetworkImageView manually once the images are downloaded? Or any other ideas?

推荐答案

This was also asked here. I finally got around to this problem by not using NetworkImageView at all. 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. 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);
}

这篇关于Recyclerview NetworkImageView(排球)未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆