Glide library

Glide library in Android with Example

What is Glide library?

Glide library is an Image Loader Library for Android, developed by bumptech, and is a Google-recommended library. It’s been used in a number of Google open-source projects. It supports animated GIFs and handles image loading/caching.

Glide is an open-source media management and image loading framework for Android that wraps media decoding, memory and disc caching, and resource pooling into a simple, easy-to-use interface.

  • Glide Android is a media management and image loading framework for Android that is open source.
  • Fetching, decoding, and displaying video stills, pictures, and animated GIFs are all supported.
  • Glide comes with a versatile API that lets developers integrate it with nearly any network stack.


Glide library dependency and repositories

repositories {

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.12.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

Basic Usage of Glide Library


Difference between Glide library and Picasso library

SyntaxIf you just want to load an image, the syntax for both libraries is nearly the same.
Both support fade animation and center cropping, and you can add a placeholder image while loading the image.
Size and Method countThe size of the glide library is nearly 3.5 times larger than the Picasso library.
Picasso library has 849 methods and glide has 2678 methods, if you want to use glide, we must enable ProGuard.
Memory ManagementGlide library uses less memory than Picasso library because it loads the same image based on the size of the view, whereas Picasso library loads the full-size image.
And if you want to avoid the OutOfMemoryError exception, we should use glide.
Image loading timePicasso library uploading time is faster than glide if the file is downloaded from the internet, but glide download time is faster if the file is downloaded from the cache.
When we try to load an image from a URL, both libraries check the local cache first, and if the image is not present in the cache, it will download from the internet because downloading glide will take time to convert and then upload but the Picasso library directly uploading that image by full size.
CachePicasso library downloads the image and stores the full-size image in the cache, and whenever we request the same image, it returns the full-size image and resizes it in real-time to fit into the Image view.
Glide, on the other hand, works differently. It downloads an image from a URL, resizes it to fit the size of the image view, and saves it to the cache. Because if we need an image in two different sizes, glide will store two different copies of the same image in the cache, each with a different resolution. This will increase the size of the disc image.
Animated Gif SupportPicasso library does not support animated gifs, but glide does.
Configuration and CustomizationGlide offers a variety of configuration and customization options.

Usage of Glide library

By- Resize:

It is not always possible to request images in perfect dimensions. If your images aren’t the right size, you can use resize(horizontal size, vertical size) to change the dimensions to a suitable size or size of your choice. This will allow you to resize the image before it is loaded into ImageView.


By- ScaleType:

In any image manipulation, resizing an image can distort its aspect ratio and make it look unappealing. When we will load an image view, and you always want to avoid this happening here, Glide provides you with options: center crop() and center inside, Fit.


It is a cropping technique that scales the image so that it crops the extra and fills only the image view’s requested bounds. Even if the entire image is not displayed, the entire image view will be filled.



It is a cropping method that scales images so that their dimensions are equal to or less than the bounds of the requested Image view. The image displayed here will be complete but will not fill the entire imageView.


Fit Center()

Scales the image uniformly (maintaining the image’s aspect ratio) so that one of the dimensions of the image will be equal to the given dimension and the other will be less than the given dimension.



Simple Placeholder()

If you’re using the Glide library, it may take a long time to load photos from the internet, depending on your user’s environment. The application’s expected behavior is to load a placeholder picture in place of the actual image until the actual image is loaded. Glide makes it simple to do so using a smooth interface that you just call.

Glide library will display a placeholder until the actual picture is loaded if you call placeHolder() with a reference to a drawable.


Error PlaceHolder()

When we’re using the Glide library to load an image into an application and your server goes down. Glide responds appropriately by providing the option of receiving an error callback.


Glide library Example in Android studio

Step-by-step explanation:

The following is an example of using the Glide library in Android, in which we will demonstrate various features provided by the Glide library.

In this case, we’ve used a simple image URL that will be loaded in imageview using the Glide library.

Step 1: Create a New Project in Android Studio.

Step 2: Open build.gradle(Module: app) and add the following dependency:

  • In this project, we will use the Picasso library for image loading.
dependencies {
  implementation 'com.github.bumptech.glide:glide:4.12.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

Step 3: Add internet permission to the AndroidManifest.xml file

  • Because we work with network operations and other such things, we require Internet connection permission.
//internet permission <uses-permission android:name="android.permission.INTERNET"/>
  • Below is the code of the AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

    <uses-permission android:name="android.permission.INTERNET" />
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />


Step 4:  In the activity_main.xml layout file, we used one image view, which will be your target imageView and where the image will be displayed, and a Button for Image loading.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=""

        app:layout_constraintTop_toTopOf="parent" />

        android:text="Load Image"
        app:layout_constraintTop_toBottomOf="@+id/ImageView" />


Step 5: In MainActivity.kt file implementing Glide library with simple image URL.

package com.sagar.glideexample

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide

class MainActivity : AppCompatActivity() {
    private lateinit var ImageView: ImageView
    override fun onCreate(savedInstanceState: Bundle?) {


    fun LoadImage(view: View) {
        ImageView = findViewById(
//                Try it yourself
//            .centerCrop()
//            .centerInside()
//            .apply(RequestOptions.overrideOf(300,300))
//            .circleCrop()
//            .fitCenter() and so on

Run the application now. You will get the output shown in the output section.

Advanced Example of Glide library–Image download from Server

We hope that this guide will assist you in quickly creating a simple Android Application using the Glide library in android. We concentrated on making a simple application for this tutorial. If you have any problems, please post them in the comments section, and we will gladly assist you.

This Post Has One Comment

Leave a Reply