Loading images in GridView using Universal Image Loader

前端 未结 2 721
臣服心动
臣服心动 2021-01-12 02:34

I\'m using the Universal Image Loader 1.8.6 library for loading dinamically images taken from web.

The ImageLoaderConfiguration configuration is the fol

相关标签:
2条回答
  • 2021-01-12 03:01

    I have solved the problem

    I was just declaring option, but I wans't using it, so I have modified the line:

    imageLoader.displayImage(basePath+immagine, iv);
    

    into:

    imageLoader.displayImage(basePath+immagine, iv, options);
    

    and I have added in the options the method:

    .cacheOnDisc(true)
    
    0 讨论(0)
  • 2021-01-12 03:10

    Caching is not enabled by default in UIL, so if you want use the cache you should use

    // Create default options which will be used for every 
    //  displayImage(...) call if no options will be passed to this method
    DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
        ...
        .cacheInMemory()
        .cacheOnDisc()
        ...
        .build();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
        ...
        .defaultDisplayImageOptions(defaultOptions)
        ...
        .build();
    ImageLoader.getInstance().init(config); // Do it on Application start
    

    And while loading image use:

    // Then later, when you want to display image
    ImageLoader.getInstance().displayImage(imageUrl, imageView); // Default options will be used
    

    Another way is

    DisplayImageOptions options = new DisplayImageOptions.Builder()
        ...
        .cacheInMemory()
        .cacheOnDisc()
        ...
        .build();
    ImageLoader.getInstance().displayImage(imageUrl, imageView, options); 
    

    And you can find more information here

    0 讨论(0)
提交回复
热议问题