Skip to content

Displaying Images with the Glide Library

Nathan Esquenazi edited this page Aug 24, 2016 · 4 revisions

Overview

Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application.

Guide is incomplete and needs attention

Setup

Add to your app/build.gradle file:

repositories {
  mavenCentral() // jcenter() works as well because it pulls from Maven Central
}

dependencies {
  compile 'com.github.bumptech.glide:glide:3.7.0'
  compile 'com.android.support:support-v4:19.1.0'
}

Basic Usage

Glide.with(context)
    .load("http://pathtoimage.com/graphic.png")
    .into(ivImg);

Advanced Usage

Resizing images with:

Glide.with(context)
    .load("http://pathtoimage.com/graphic.png")
    .override(300, 200)
    .into(ivImg);

Placeholder and error images:

Glide.with(context)
    .load("http://pathtoimage.com/graphic.png")
    .placeholder(R.drawable.placeholder)
    .error(R.drawable.imagenotfound)
    .into(ivImg);

Cropping images with:

Glide.with(context)
    .load("http://pathtoimage.com/graphic.png")
    .centerCrop()
    .into(ivImg);

Transforming images with:

Glide.with(context)
    .load("http://pathtoimage.com/graphic.png")
    .transform(new CircleTransform(context))
    .into(ivImg);

Configuration

You can configure Glide by creating a GlideConfiguration.java file:

public class GlideConfiguration implements GlideModule {

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        // Apply options to the builder here.
        // Glide default Bitmap Format is set to RGB_565 since it 
        // consumed just 50% memory footprint compared to ARGB_8888.
        // Increase memory usage for quality with:
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    }

    @Override
    public void registerComponents(Context context, Glide glide) {
        // register ModelLoaders here.
    }
}

And then define it as meta-data inside AndroidManifest.xml:

References

Finding these guides helpful?

We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.

Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.

Interested in ramping up on Android quickly?

(US Only) If you are an existing engineer with 2+ years of professional experience in software development and are serious about ramping up on Android quickly, be sure to apply for our free evening 8-week Android bootcamp.

We've trained over a thousand engineers from top companies including Apple, Twitter, Airbnb, Uber, and many others leveraging this program. The course is taught by Android experts from the industry and is specifically designed for existing engineers.

Not in the United States? Please fill out our application of interest form and we’ll notify you as classes become available in your area powered by local organizers.

Clone this wiki locally