Use a thumbnail as a placeholder for Picasso

后端 未结 3 1432
太阳男子
太阳男子 2021-02-02 03:49

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 f

3条回答
  •  梦毁少年i
    2021-02-02 04:34

    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() {
    
                }
            });
    

    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

    -- update --

    I've made a blog post describing the whole scenario

提交回复
热议问题