Load Gif in ImageView Android – Java & Kotlin

In this article, we will learn the easiest way to load Gif Images in ImageView in Android. We will use Glide Image loading & caching library to load Gif in Android. As we all now that directly we cannot load a Gif image in ImageView in Android. So mostly it’s suggested to use Webview to load Gif images in Android. But I prefer to use the Glide library to load Gif in Android ImageView.

Import Glide Library in Your Project

To import Glide Android SDK in your project add the following dependency in your build.gradle file. Firstly, In your Project Level build.gradle file, make sure you have added the following repositories.

repositories {
  google()
  jcenter()
}

Now In your App Level build.gradle file add the following dependencies.

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

Sync your gradle and move to next step.

Load Gif Locally From Your Project in Android Studio

We can put a Gif Image in our project in Android studio or we also can load Gif from a remote URL. If you want to put Gif in your Project then follow the below steps.

1. Create Assets Folder in Android Studio

If you don’t already have an assets folder in your project, we need to create it first. For that in left Project Inspector, Right-click on your App folder then navigate to New -> Folder -> Assets Folder as shown in the following Screenshot.

Create Assets Folder in Android Studio

2. Copy Gif Image in Assets Folder

Now Just drag and drop your gif images into the newly created assets folder which you will see with the res folder.

3. Local Local Gif Image through Glide

Now add a normal ImageView in your Activity’s or Fragment’s XML and get its reference and load Gif image in the following way.

JAVA

Glide.with(this).load("file:///android_asset/your_gif_file_name.gif").into(YOUR_IMAGE_VIEW_OBJECT);

KOTLIN

Glide.with(this).load("file:///android_asset/your_gif_file_name.gif").into(YOUR_IMAGE_VIEW_OBJECT);

Load Gif Image From Remote URL

Loading gif image through the remote URL is also the same as loading from the local assets folder. We only need to replace the local path with the server gif URL as shown in the following code.

JAVA

Glide.with(this).load("https://media.giphy.com/media/SKGo6OYe24EBG/giphy.gif").into(YOUR_IMAGE_VIEW_OBJECT);

KOTLIN

Glide.with(this).load("https://media.giphy.com/media/SKGo6OYe24EBG/giphy.gif").into(YOUR_IMAGE_VIEW_OBJECT);

That’s it. Enjoy 🙂

Feel free to ask questions or give suggestions in the comments section below.

Next:

Pick Image From Gallery in Kotlin – Android

Please share this post:
Native Mobile Application Developer (Android + IOS) having experience in Java, Swift, Kotlin, Objective C, Unity, C#, C/C++, NODE JS & PHP.

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: