【问题标题】:How to cache profile picture with Picasso in MaterialDrawer library如何在 MaterialDrawer 库中使用 Picasso 缓存个人资料图片
【发布时间】:2016-03-11 04:11:20
【问题描述】:

我正在使用MaterialDrawer 库并使用Picasso 加载配置文件图像。但是我无法使用 Picasso 将其保存在本地并在将来从缓存中加载它。

在创建抽屉之前,

 //below line is for loading profile image from url
    DrawerImageLoader.init(new DrawerImageLoader.IDrawerImageLoader() {
        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }

        @Override
        public Drawable placeholder(Context ctx) {
            return null;
        }

    });

我按照材料库的说法写了这个。然后我设置了我的头像:

String myURL = "http://www.american.edu/uploads/profiles/large/chris_palmer_profile_11.jpg" profile = new ProfileDrawerItem().withName(person.getFullName()).withEmail(person.getStMajorName()).withIcon(myURL)

但每次我运行该应用程序时,它都会从互联网加载它。

如何缓存图片?

【问题讨论】:

  • 你怎么知道它每次都是从互联网加载的?
  • 通常毕加索会关心缓存和一切。并且 MaterialDrawer 不会修改此行为。您确定缓存不起作用吗?其他尝试 Glide 吗?

标签: android caching navigation-drawer picasso materialdrawer


【解决方案1】:

默认情况下,Picasso 带有适用于大多数用例的默认实现。

有多种解决方案可让您强制Picasso 从缓存中加载图像。或者改变这种行为。

您应该查看以下 StackOverFlow 问题,这些问题提供了针对您的问题的不同解决方案:

How do I use disk caching in Picasso?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 2017-09-30
    • 2018-11-19
    • 2023-03-28
    相关资源
    最近更新 更多