简体   繁体   中英

Picture lazy loading in android

I'm developing an App on which I have plenty of ListViews. On each ListView Item, there is a picture. In order to load the pictures from the server taking in consideration:

  • Basic Authentication.
  • SSL certification.

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. 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

You can also user Fresco ( https://github.com/facebook/fresco ) with OkHttp: 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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