微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android Picasso将先前加载的图像设置为占位符

如何解决Android Picasso将先前加载的图像设置为占位符

我正在使用Picasso加载质量较低的图像版本,如果用户在列表中单击该图像,则会打开新的Activity,在此处我还将显示图像的完整质量版本Picasso

问题在于图像的完整质量版本很大,因此加载它需要一些时间。

我希望在此期间显示以前加载的较​​小质量版本的图像。毕加索会立即显示它,因为它已经加载到以前的活动中。

我试图通过两次调用Picasso方法来实现它:

Picasso.get().load(url_small_quality).into(imageView)
Picasso.get().load(url_full_quality).into(imageView)

但是我认为它会跳过load(url_small_quality),因为imageView在为url_full_quality加载之前一直为空。

我尝试只运行load(url_small_quality),然后立即加载图像,因为它是先前加载和存储的。

是否有办法将以前加载的较​​小质量的图像设置为占位符,直到加载完整质量的图像?

解决方法

毕加索很可能正在取消您之前的请求,您可以尝试

 Picasso.get().load(url_small_quality).into(imageView,object:Callback{
            override fun onSuccess() {
                Picasso.get().load(url_full_quality).into(imageView)
            }

            override fun onError(e: Exception?) {
              
            }

        })
,
  1. 您可以将drawable用作占位符,但这将是默认图像

        Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
    
  2. 您可以在成功加载如下所示的低质量图像之后加载高质量图像(由于没有直接方法可以实现此目的,因此可以使用磁盘缓存,但这需要更多的努力):->

        Picasso.with(context)
        .load(thumb) // small quality url goes here
        .into(imageView,new Callback() {
             @Override
             public void onSuccess() {
                 Picasso.with(context)
                         .load(url) // full quality url goes here
                         .placeholder(imageView.getDrawable())
                         .into(imageView);
             }
             @Override
             public void onError() {
    
             }
         });
    
,

正如 Astha Garg 在评论中所说,这是不可能的:

Picasso.get().load(url_small_quality).into(imageView)
Picasso.get().load(url_full_quality).into(imageView)

只需再创建一个图像视图,然后用拇指将其放在前一个图像视图之上,然后在那里加载高分辨率。

Java:

Picasso.get().load(url_small_quality).into(IVThumb,new Callback() {
    @Override
    public void onSuccess() {
        Picasso.get().load(url_full_quality).into(IVFull,new Callback() {
            @Override
            public void onSuccess() {

            }
            @Override
            public void onError(Exception e) {

            }
        });
    }
    @Override
    public void onError(Exception e) {

    }
});

xml:

在 LinearLayout 中创建:

<ImageView
    android:id="@+id/IVThumb"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<ImageView
    android:id="@+id/IVFull"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。