In this tutorial you will learn how to use Glide in several scenarios. Follow the quick examples and snippets to learn how to use Glide.

Quick Glide Examples

1. How to Display Image with Glide

Here’s a static method to load an image into an imageview. You provide a url and the imageview and Glide will load the image, showing a placeholder as the image loads.

You can also set the cache strategy:

    public static void displayImage(String url,ImageView imageView) {

        Glide.with(MainApp.getContext())
                .load(url)

                .placeholder(R.drawable.pictures_no)
                .thumbnail(0.2f)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);

    }
2. How to Display Image referer
    public static String UserAgent="Mozilla/5.0 (Linux; U; Android 2.1; en-us; GT-I9000 Build/ECLAIR) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2";
    public static void displayImageReferer(String url,ImageView imageView,String referer) {
        if(url==null){
            return;
        }
        LazyHeaders.Builder builder=new LazyHeaders.Builder().addHeader("User-Agent", UserAgent);
        if(referer!=null){
            builder.addHeader("Referer", referer);
        }

        GlideUrl glideUrl = new GlideUrl(url,builder.build());

        Glide.with(MainApp.getContext())
                .load(glideUrl)
                .placeholder(R.drawable.pictures_no)
                .thumbnail(0.2f)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);

    }
3. How to Display a Gif Image with Glide
    public static void displayImageGif(String url,ImageView imageView) {

        Glide.with(MainApp.getContext())
                .load(url)
                .thumbnail(0.2f)
                .placeholder(R.drawable.pictures_no)
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);

    }
4. How to Load Bitmap into ImageView via Glide
    public static void displayImageBitmap(String url,ImageView imageView) {

        Glide.with(MainApp.getContext())
                .load(url)
                .asBitmap()
                .thumbnail(0.2f)
                .placeholder(R.drawable.pictures_no)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);

    }
5. How to Load Bitmap Captcha into ImageView via Glide
    public static void displayImageBitmapCaptcha(String url, ImageView imageView) {

        Glide.with(MainApp.getContext())
                .load(url)
                .asBitmap()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);

    }
6. How to Display thumbnail into ImageView via Glide
    public static void displayImageThumb(String url,ImageView imageView) {

        Glide.with(MainApp.getContext())
                .load(url)
                .asBitmap()
                .thumbnail(0.2f)
                .placeholder(R.drawable.pictures_no)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);

    }