android - android中的图片懒加载

标签 android ssl lazy-loading basic-authentication ui-thread

我正在开发一个有大量 ListView 的应用程序。在每个 ListView Item 上,都有一张图片。为了从服务器加载图片考虑到:

  • 基本身份验证。
  • SSL 认证。

我想知道最好的方法是什么。我尝试制作一个使用 Volley 库中的 ImageRequest 的递归方法,但它似乎有点阻塞了 UI 线程...... 我也尝试过 Picasso,它允许异步加载图片,这要归功于 ImageView 和请求之间的关联,无法使其与基本身份验证一起使用并忽略 SSL 认证。 Here is my not solved problem

我正在寻找其他解决方案...所以如果有人有想法,将不胜感激...

提前致谢!

最佳答案

毕加索是神解。要添加自定义 header ,只需使用您自己的下载器。

OkHttpClient picassoClient = client.clone();
picassoClient.interceptors().add(new MyInterceptor());
// ...
new Picasso.Builder(context).downloader(new OkHttpDownloader(picassoClient)).build();

阅读本期内容:https://github.com/square/picasso/issues/900

您还可以使用 OkHttp 来使用 Fresco ( https://github.com/facebook/fresco ): http://frescolib.org/docs/using-other-network-layers.html

Context context;
OkHttpClient okHttpClient; // build on your own
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
    .newBuilder(context, okHttpClient)
    . // other setters
    . // setNetworkFetcher is already called for you
    .build();
Fresco.initialize(context, config);

关于android - android中的图片懒加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32207703/

相关文章:

android - 如何在 android 中玩 .pls?

Spring Boot 2 tomcat ssl握手缓存

java - 即使我通过打印每个元素进行验证后,Iterable 也会抛出 NoSuchElementException

android - 在 Android 中动态地向资源字符串数组添加值

android - 如何在X86 linux中调用android动态库(.so)?

android - 保存的游戏 + 实时多人 Android

apache - 使用 Docusign API curl SSL 相关连接超时

ssl - Ubuntu 14.04.2 上的 Citrix Receiver 失败并出现错误委托(delegate)证书颁发机构 - L1K SSL 错误 61

java - 潮人。二级缓存。实体未找到异常

html - 在将实际图像加载到框架之前,如何根据 CSS 使浏览器缩放图像框架?