如何在毕加索中添加缓存功能?

时间:2018-10-25 10:47:29

标签: android picasso image-caching

如何执行以下任务

使用图像缓存框架和网络框架吗?

在我的实现下方

Picasso.get().load(introduction.getImage()).into(holder.imageView);

我找到了这个样本:

Picasso.with(context)
                    .load(Uri.parse(getItem(position).getStoryBigThumbUrl()))
    .networkPolicy(NetworkPolicy.OFFLINE)
    .into(holder.storyBigThumb, new Callback() {
        @Override
        public void onSuccess() {

        }

        @Override
        public void onError() {
            // Try again online if cache failed
            Picasso.with(context)
                    .load(Uri.parse(getItem(position)
                            .getStoryBigThumbUrl()))
            .placeholder(R.drawable.user_placeholder)
            .error(R.drawable.user_placeholder_error)
                    .into(holder.storyBigThumb);
        }
    });

1 个答案:

答案 0 :(得分:0)

  

您可以将NetworkPolicy.OFFLINEPicasso一起使用。

if (introduction.getImage() != null) {
            Picasso.get().load(introduction.getImage()).resize(100, 100).centerCrop().
                    networkPolicy(NetworkPolicy.OFFLINE).into(holder.imageView, new Callback() {
                @Override
                public void onSuccess() {

                }

                @Override
                public void onError(Exception e) {
                    Picasso.get().load(R.drawable.ic_contact).resize(100, 100).centerCrop().
                            into(holder.imageView);
                }
            });

        }