简体   繁体   English

图片在Android中延迟加载

[英]Picture lazy loading in android

I'm developing an App on which I have plenty of ListViews. 我正在开发一个有很多ListViews的应用程序。 On each ListView Item, there is a picture. 在每个ListView项上都有一张图片。 In order to load the pictures from the server taking in consideration: 为了从服务器加载图片,请考虑以下因素:

  • Basic Authentication. 基本身份验证。
  • SSL certification. SSL认证。

I would like to know what is the best way to do that. 我想知道什么是最好的方法。 I've try to make a recursive method which uses ImageRequest from Volley Library but it seems like it is a little bit blocking the UI Thread... I've tried Picasso also which allows to load asynchronously pictures thanks to an association between the ImageView and the request by couldn't make it work with Basic Authentication and by ignoring SSL Certification. 我尝试制作一种使用Volley Library中的ImageRequest的递归方法,但似乎有点阻塞了UI线程...我尝试了Picasso,由于ImageView之间的关联,它也允许异步加载图片并且该请求不能通过基本身份验证和忽略SSL认证来使其生效。 Here is my not solved problem 这是我未解决的问题

I'm looking for some other solutions... So If someone has an idea, would be really appreciated... 我正在寻找其他解决方案...所以,如果有人有想法,将不胜感激...

Thanks in advance ! 提前致谢 !

Picasso is a god solution. 毕加索是上帝的解决方案。 To add a custom header just use your own downloader. 要添加自定义标头,只需使用自己的下载器即可。

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

Read about that in this issue: https://github.com/square/picasso/issues/900 在本期中阅读有关此内容的信息: https : //github.com/square/picasso/issues/900

You can also user Fresco ( https://github.com/facebook/fresco ) with OkHttp: http://frescolib.org/docs/using-other-network-layers.html 您还可以通过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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM