使用Picasso库无法将图像加载到android 5.0中 [英] Images are not loading in android 5.0 using picasso library

查看:70
本文介绍了使用Picasso库无法将图像加载到android 5.0中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Picasso库v2.5.2的演示应用程序上工作.在所有android操作系统版本上都可以正常运行,但在棒棒糖上则不能.

I am working on demo application in which I am using Picasso library v2.5.2. It is working fine on all android operating system version, but not in lollipop.

大小为130KB的图片尚未为我加载.尺寸较小的图像可以正确加载.

这是我下载位图并在imageview上设置的代码.

Here is my code for downloading bitmap and set on imageview.

target = new Target() {
    @Override
    public void onPrepareLoad(Drawable drawable) {}

    @Override
    public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
        if(bitmap != null) {
            imageView.setImageBitmap(bitmap);
        }
    }

    @Override
    public void onBitmapFailed(Drawable drawable) {}
};

Picasso.with(this).load(URL).into(target);

我不确定与此相关的其他东西,以便我也可以使用棒棒糖,或者这是lib中的错误?

I'm not sure what extra stuff I have to do with this so that I will work on lollipop also or this is bug in lib ?

推荐答案

这是一个已知问题.问题在于,毕加索为Target保留了较弱的引用.要使其正常工作,您需要使其坚固,例如通过存储Target作为视图标签.

It's a known problem. The problem is that Picasso keeps a weak reference for the Target. To get it working you need to make it strong, by storing a Target as a tag of view, for example.

target = new Target() {
    @Override
    public void onPrepareLoad(Drawable drawable) {}

    @Override
    public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
        if(bitmap != null) {
            imageView.setImageBitmap(bitmap);
        }
    }

    @Override
    public void onBitmapFailed(Drawable drawable) {}
    };

imageView.setTag(target);
Picasso.with(this).load(URL).into((Target) imageView.getTag());

我建议您使用 Glide ,它与毕加索非常相似,也是Google推荐的.正如您在此线程的结尾看到的那样,原始开发人员解决了该BitmapFactory使用额外的缓冲区会出现问题.

I suggest you to use Glide, it's very similar to Picasso, and also recommended by Google. And as you can see in the end of this thread, the original developer solves this BitmapFactory problem by using extra buffer.

这篇关于使用Picasso库无法将图像加载到android 5.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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