【问题标题】:How to display image in appwidget listview without reload it using Picasso android如何在appwidget listview中显示图像而不使用Picasso android重新加载它
【发布时间】:2016-12-16 13:08:47
【问题描述】:

您好,我在使用 Picasso 的 appwidget listview 项目中有缩略图。但它在滚动列表视图时显示为正在加载。我使用下面的代码在 RemoteViews getViewAt(int position) 方法中加载图像,

try {
                Bitmap b = Picasso.with(context).load(url).get();
                remoteView.setImageViewBitmap(R.id.feed_image, b);
            } catch (Exception e) {
                e.printStackTrace();
            }

有没有办法将它存储在缓存中并避免重新加载?请给我一个想法。

【问题讨论】:

  • 这里,不需要在imageview设置位图。可以直接使用Picasso或Glide加载URL。
  • @ViramP 你能告诉我怎么做吗?
  • 您找到解决方案了吗? @Sangeetha

标签: android android-widget android-appwidget-list


【解决方案1】:

尝试将图像直接加载到您的视图中。试试这个:

String url= "your img url here";
Picasso.with(context).load(url).into(remoteView);

这将自动缓存图像,滚动不会发出额外的网络请求,它只会检查它是否已经在缓存中。

在此处查找更多信息:https://guides.codepath.com/android/Displaying-Images-with-the-Picasso-Library

【讨论】:

  • 这适用于普通视图。我正在使用小部件列表视图,我可以在其中访问这样的视图 remoteView.setImageViewBitmap(R.id.feed_image, b);所以我不能像你指定的那样使用remoview,这是我的主要问题。
猜你喜欢
  • 2017-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-29
  • 1970-01-01
  • 2019-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多