Android Imageloader configuration implementation code
ImageLoader Advantages
(1) Support download progress monitoring
(2) You can pause image loading in View scrolling
The PauseOnScrollListener interface allows you to pause image loading in View scrolling.
(3) By default, multiple memory cache algorithms can be configured with cache algorithms for these image caches, but ImageLoader implements more cache algorithms by default, such as Size
Delete the maximum first, delete the minimum first, use the minimum most recently, delete the first first, delete the maximum first time, etc.
(4) Support local cache file name rule definition
Implementation code:
/** * Initialize ImageLoader */ public static void initImageLoader(Context context) { File cacheDir = (context, "bee_k77/Cache");// Get the cached directory address ("cacheDir", ()); // Create a configuration ImageLoader (all options are optional, only those you really want to customize). This can be set in APPLACATION and set as global configuration parameters ImageLoaderConfiguration config = new ( context) // max width, max height, that is, the maximum length and width of each cache file saved .memoryCacheExtraOptions(480, 800) // Can slow ImageLoader, use it carefully (Better don't use it) Set the cache details, it is best not to set this/ .discCacheExtraOptions(480, 800, , 75, null) // The number of loads in the thread pool .threadPoolSize(3) // Thread priority .threadPriority(Thread.NORM_PRIORITY - 2) /* * When you display an image in a small ImageView * and later you try to display this image (from identical URI) in a larger ImageView * so decoded image of bigger size will be cached in memory as a previous decoded image of smaller size. * So the default behavior is to allow to cache multiple sizes of one image in memory. * You can deny it by calling this method: * so when some image will be cached in memory then previous cached size of this image (if it exists) * will be removed from memory cache before. */ / .denyCacheImageMultipleSizesInMemory() // You can pass your own memory cache implementation you can implement it through your own memory cache // .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // .memoryCacheSize(2 * 1024 * 1024) //Hard disk cache 50MB .diskCacheSize(50 * 1024 * 1024) //Use MD5 to save the URI name .diskCacheFileNameGenerator(new Md5FileNameGenerator()) // Encryption .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())//Encrypt the URI name when saved with HASHCODE .tasksProcessingOrder() .diskCacheFileCount(100) //The number of cached files .diskCache(new UnlimitedDiscCache(cacheDir))// Custom cache path // .defaultDisplayImageOptions(()) // .imageDownloader(new BaseImageDownloader(context, 5 * 1000, // 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s) timeout .writeDebugLogs() // Remove for release app .build(); // Initialize ImageLoader with configuration. ().init(config);// Initialize this configuration globally}
Option class
package ; import ; import com.; import com.; import com.; import ; public class Options { /** * Image loading configuration used in the news list */ public static DisplayImageOptions getListOptions() { DisplayImageOptions options = new () // Set the picture to display during download .showImageOnLoading(.ic_stub) // Set the picture to be displayed when the picture Uri is empty or wrong .showImageForEmptyUri(.ic_stub) // Set the picture displayed during error during picture loading/decoding .showImageOnFail(.ic_error) // Set whether the downloaded image is cached in memory .cacheInMemory(false) // Set whether the downloaded pictures are cached in the SD card .cacheOnDisc(true) // Keep Exif information .considerExifParams(true) // Set how the picture is displayed in encoding .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) // Set the decoding type of the picture .bitmapConfig(.RGB_565) // .decodingOptions( // decodingOptions)// Set the decoding configuration of the picture .considerExifParams(true) // Set the delay before image download .delayBeforeLoading(100)// int // delayInMillis sets the delay time for you // Set the bitmap before adding the image to the cache // .preProcessor(BitmapProcessor preProcessor) .resetViewBeforeLoading(true)// Set whether the image is reset before downloading, reset // .displayer(new RoundedBitmapDisplayer(20))// Whether to set it to rounded corners and what is the radian .displayer(new FadeInBitmapDisplayer(100))// Fade in .build(); return options; } }
Thank you for reading, I hope it can help you. Thank you for your support for this site!