Hey friends, in this post, we will see how to load image from URL in android using Glide library. Glide is an image loading library which can be used to load an image to the imageview, from an URL. After loading the image from the URL, it basically stores that image loaded, in a cache which can be later viewed when there is no internet connection.
This post is divided into 4 parts
- Adding the Glide Library to your project
- Registering an imageview object with glide
- Loading image into the imageview object with Glide (Internet Connection)
- Loading image into the imageview object (No Internet Connection)
Why load image from URL in android using Glide?
- Fast and efficient open source library for image loading and disk caching.
- Simple and easy to use interface
Step1 – Adding Glide Library to your project
Go to app level Gradle, from your android studio, in your project and then add the below line.
Now go to manifest, and then give the internet permissions
<uses-permission android:name="android.permission.INTERNET" />
Step2- Registering Imageview object with Glide
ImageView im= (ImageView) findViewById(R.id.im);
- load() – Here you can specify the URL String
- placeholder() – You can specify the loading image
- error() – You can specify the image when URL fails to load
- into() – Here you need to specify the target ImageView.
Now install the application in your android, turn on the internet and you can see the image gets loaded. Next time when you reopen, the same app, you don’t need any internet connection because, the image has already been stored in the cache.