Downloading and Showing Image with Glide Library in Android

Downloading and Showing Image with Glide Library in Android

Today, we are having mobile applications for each and every task that we do throughout the day. And we love to use the application that is more interactive and have better UI. And the most important thing that makes an App more interactive is the use of images.

Yes, images play a major role in making the UI of an App more interactive and user-friendly. So, as an Android Developer, we should take care of using images in our App. We should handle each and every aspect of an image like the slow loading aspect, unresponsive image, memory issues and many more. If you are not handling these aspects, then your app will have a bad impression on your users.

In order to manage every aspect of images that are used in Android Application, Google recommended the use of Glide library in the Google I/O 2014. So, in this blog, we will learn how to use Glide libraries to download image and use it in our application. The outline of this blog is as follows:

  • What is Glide?
  • Features of Glide Library
  • Glide usage in Android
  • Some more features
  • Conclusion

What is Glide?

To be more precise, Glide is an open source media management framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

In other words, Glide Library is a popular android library for image downloading and caching and is developed by bumptech . It is basically focused on smooth scrolling. Many times, it is found that if you try to load an image of a very big size, then your app will not be smooth. The scrolling will not be smooth but by using Glide you can get rid of this problem.

The primary focus of Glide is to make scrolling smooth and as fast as possible. But Glide can also be used for fetching, resizing and displaying a remote image.

Features of Glide Library

Glide supports a large number of features. Some of these are:

  • Use of GIF: In Glide, you can use GIF also. Gone are the times, when you put a static image to your app. Now, you can use GIF using Glide.
  • Disk caching: Glide downloads the image from the given URL, resize it to the size of the image view where you want to display the image and stores it to the disk cache. Glide will store two different copies of same image if you are putting the same image in two different Image Views. That will increase the disk cache size, but it will increase the processing speed.
  • Thumbnail support: With Glide, we can load multiple images into the same view at the same time i.e we can add thumbnails to our image view.
  • Customization: The best thing about Glide is, it provides various configurations and customization options. So, you can change the Glide library as per your requirement.

Glide usage in Android

Int his section of this bolg, we will look upon the implementation of Glide in Android using Kotlin. To use Glide library in your Android application, first of all, add the Glide library dependency to your app/build.gradle file:

dependencies {
   //glide library
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

Now after adding the above dependency, sync your project. This will add the Glide library to your project. After that, add internet permission in AndroidManifest.xml . This is required because we need the internet to download the image:

<uses-permission android:name="android.permission.INTERNET"/>

Now, you are done with all the dependencies and permissions. It’s time to code for the Glide library. In the glide_example.xml write the following code to add a LinearLayout. We will use this Linearlayout to display the downloaded image:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

Till now we are done with the UI part. Now in the GlideExample.kt file, add the below lines:

class GlideExample : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        val linearLayout = findViewById<LinearLayout>(
        val imageView = ImageView(this)

Let’s understand the above code. In the above code, we created an instance of LinearLayout to display the downloaded image. To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView .

Some more features

  • Resizing image: You can resize an image using the override() method that will take the final dimensions of the image.
        .override(300, 200)
  • Adding placeholder and error message: Adding a placeholder for an image is always a nice option because there may arise a case when the internet speed is slow and in that condition, your image will not be loaded in few seconds. So, to handle those situations we use some placeholder that will be displayed until your original image will be loaded.Also if there is some error during the image fetching then the user should know that some error has occurred. That error may arise due to the wrong URL or due to no internet connectivity. To set a placeholder and an error, use the following:
        .placeholder(R.drawable.placeholder) //placeholder
        .error(R.drawable.error) //error
  • Crop an image: You can crop an image using the centerCrop() method:
  • Adding a progress bar: Adding a progress bar until the image is loading is always a good to have choice. So, to add a progress bar while the image is downloading, we use the same approach as used in error setting:

        .listener(new RequestListener<Drawable>() {
            public boolean onLoadFailed(Exception e, Object model, Target<Drawable> target, boolean isFirstResource) {
                return false; // important to return false so the error placeholder can be placed

            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                return false;

There are many other method that you can use in Glide library, some of those are fitCenter(), centerCrop(), etc. You can find them here .


In this blog, we have seen how to use the Glide library to download and show an image in an ImageView. Images are loaded from the internet and we have given access for the App to connect the internet. All the complex work of loading and handling the images are done by the Glide library. So, without putting much effort, we learned how to handle images in our Andoird project and I am pretty sure that you will explore some more methods of Glide library.

Till then, Keep Learning!

Team MindOrks :)