Android Glide Tutorial with Example

Here you will get android glide tutorial with example.

Glide is an android library that allows us to fetch image from internet or url in single line of code. In one of my previous tutorial I have shown you the usage of picasso image library. Glide is a good alternative of Picasso library. Most of the features are common in both of them.

Glide is popular android image library which is recommended by Google and even Google used it in various applications. Below are some features of this library.

Android Glide Tutorial with Example

Features of Glide Image Library

  • Supports fetching of images, gifs and video stills.
  • Placeholder and error image can be added.
  • Support disk caching.
  • Image resize and cropping.

One of the biggest advantage of Glide over Picasso is that Glide supports gifs.

Android Glide Tutorial

Lets quickly jump to the actual tutorial part.

How to fetch image using Glide?

For this you just have to use one line of code given below.

Placeholder and Error Image

You can add a placeholder image until the image loaded from internet. You can also add an error image in case any error occurs while fetching image.

Loading GIFs

You can load a gif by just adding asGif() method.

Resizing and Cropping Image

The following line of code resizes image to 300×300 pixel and make it center cropped.

Android Glide Example

Lets make a simple android app that shows the usage of Glide image library.

1. Create an android studio project with package name com.androidglide

2. Now include Glide library to your project by adding following line of code under dependencies section in app level build.gradle file.

3. Add internet access permission in AndroidManifest.xml file.

4. Add following code in respective files.

activity_main.xml

MainActivity.java

5. Save and run the project.

The image is fetched from internet on button click, see below screenshot.

Screenshot

Android Glide Tutorial with Example

Comment below if you have any queries related to above glide android tutorial.

1 thought on “Android Glide Tutorial with Example”

Leave a Comment

Your email address will not be published. Required fields are marked *