Image loading framework: Picasso, Glide, or even the classic image-loader that is no longer maintained.Glide is Google’s recommended Image loading framework, so it’s worth checking it out.


Glide. With (context).url(url).into(imageview); So we can load a web image, isn’t that easy? Remember to add network privileges. Glide is far more powerful than this.

  • Set up the placeholder mapIf we want to set the imageView to a default image when loading the image, just:Glide.with(this).load(url).placeholder(R.drawble.place).into(imageview);
  • Setting the wrong picture: When the network error or some reason caused the image load failure to set the wrong image we just need:Glide.with(this).load(url).. centerCrop().placeholder(R.drawble.place).error(R.drawble.load.error).into(imageview);
  • Loading local imagesTo load a local image, just pass in a file:Glide.with(context).load(file).into(imageview);
  • Loading GIF images; Glide support for loading GIF images, as usual, just pass in the URL:Glide.with(this).load(GifUrl).into(imageview);Glide also supports loading local imagesThe first frame, so that we can use the video as a thumbnail, also in the same way as the local image to pass file:Glide.with(context).load(VideoFile).into(imageview);# Ultimate usage:
  • Image processing: Glide also provides a way to process our images when we have special requirements (such as round heads, Gaussian blur, etc.) : It inherits BitmapTransformation to preprocess the image;
public class BitmapTransform extends BitmapTransformation { @Override protected Bitmap transform(BitmapPool pool, Override public String Bitmap toTransform, int outWidth, int outHeight) {//toTransform is a pre-treated Bitmap} @override public StringgetId() {}}Copy the code

You can do things like Gaussian blur, circles, or rounded corners in this library. You can make quick changes to everything you want.

  • Custom Glide: We generally use A simple Glide that has the image quality configured by default, image caching, etc. When we need to customize, we can implement the GlideModule class to do so. Such as:
public class MyGlideModule implements GlideModule {

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
       // You can use GlideBuilder to set custom properties, such as:
        builder.setDiskCache();// Customize the disk cache
        builder.setMemoryCache();// Custom memory cache
         builder.setDecodeFormat();// Customize image quality
        // There are others to check for yourself.

    }

    @Override
    public void registerComponents(Context context, Glide glide) {}}Copy the code

** Note: Custom Modules need to be configured in the AndroidManifest, add under the application node:
Multiple GlideModule, **, can be customized in the manifest file