Glide, just like Picasso, can load and display images from many sources, while also taking care of caching and keeping a low memory impact when doing image manipulations. It has been used by official Google apps (like the app for Google I/O 2015) and is just as popular as Picasso. In this series, we're going to explore the differences and advantages of Glide over Picasso.
Glide Series Overview
- Upgrade Guide from Glide 3.x (Coming soon)
- Getting Started
- Advanced Loading
Why Use Glide?
Experienced Android developers can skip this section, but for the starters: you might ask yourself why you want to use Glide* instead of your own implementation.
Android is quite the diva when working with images, since it'll load images into the memory pixel by pixel. A single photo of an average phone camera with the dimensions of 2592x1936 pixels (5 megapixels) will allocate around 19 MB of memory. If you add the complexity of network requests on spotty wireless connections, caching and image manipulations, you will save yourself a lot of time & headache, if you use a well-tested and developed library like Glide.
In this series, we'll look at many of the features of Glide. Just take a peek at the blog post outline and think if you really want to develop all of these features yourself.
* = or any other image loading library, like Picasso, ION, etc.
Adding Glide to Your Setup
Hopefully by now we've convinced you to use a library to handle your image loading requests. If you want to take a look at Glide, this is the guide for you!
First things first, add Glide to your dependencies. At the time of writing, the last version of Glide is
As with most dependencies, pulling it in a Gradle project is a single line in your
While we moved all our projects to Gradle, Glide also supports Maven projects:
<dependency> <groupId>com.github.bumptech.glide</groupId> <artifactId>glide</artifactId> <version>3.8.0</version> <type>aar</type> </dependency>
First Peek: Loading Image from a URL
Just like Picasso, the Glide library is using a fluent interface. The Glide builder requires at least three parameters for a fully functional request:
with(Context context)- Context is necessary for many Android API calls. Glide is no difference here. Glide makes this very convenient by also extracting the context if you pass an
load(String imageUrl)- here you specify which image should be loaded. Mostly it'll be a String representing a URL to an Internet image.
into(ImageView targetImageView)- the target ImageView your image is supposed to get displayed in.
Theoretical explanations are always harder to grasp, so let's look at a hands-on example:
ImageView targetImageView = (ImageView) findViewById(R.id.imageView); String internetUrl = "http://i.imgur.com/DvpvklR.png"; Glide .with(context) .load(internetUrl) .into(targetImageView);
That's it! If the image at the URL exists and your
ImageView is visible, you'll see the image in a few seconds. In case the image does not exist, Glide will return to the error callbacks, which we'll look at later. You might already be convinced with this three-line example that Glide is useful to you, but this is just the tip of the feature iceberg.
In our next post, we'll start by looking at other options to load images, besides from an Internet URL. Specifically, we'll load an image from Android resources, local files and a Uri.