将缩略图用作毕加索的占位符

问题描述:

从UX的角度来看,最好先向用户显示缩略图,直到真实图像完成加载,然后再向用户显示缩略图,但是

From the UX point of view, it will be great to show the user a thumbnail first until the real image completes loading, then showing it to him, but Picasso uses only a resource file as the place holder like:

Picasso.with(context)
    .load(url)
    .placeholder(R.drawable.user_placeholder)
    .into(imageView);

那么,如何使用缩略图URL作为占位符? ,如果我应该两次使用毕加索,那怎么办?

So, how can I use a thumbnail URL as the placeholder? , and if I should use Picasso twice, then how?

问题已经在毕加索的github页面上打开了此请求,但似乎不会根据JakeWharton添加到毕加索.那么,我们如何才能利用现有的可用资源呢?

An issue is already opened on Picasso's github page with this request, but seems it won't be added to Picasso as per JakeWharton. So how could we do it with what's available in hand?

感谢在这里&关于github上原始请求的评论,最后我有了一个可行的解决方案:

Thanks to raveN here & the comments on the original request on github, finally I've got a working solution:

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

            }
        });

此处的窍门是在第一次调用&之后,从imageView(即缩略图)获取可绘制对象将其作为占位符传递给第二个呼叫

The trick here is to get the drawable from the imageView (which is the thumbnail) after the first call & pass it as a placeholder to the second call

-更新-

我已经制作了博客文章描述了整个场景

I've made a blog post describing the whole scenario