How to Use Universal Image Loader Library in Android?
UIL (Universal Image Loader) is a similar library to that of Picasso and Glide which performs loading images from any web URL into ImageView of Android. This image loading library has been created to provide a powerful, flexible, and customizable solution to load images in Android from Server. This image loading library is being created by an indie developer and it is present in the top list of GitHub. Features of UIL (universal Image Loader) library:
- This library provides Multi-thread image loading.
- Image caching can be done in memory and on the user’s device.
- Listening loading process (including downloading progress).
- Many customizable features are available for every display image call.
Note: We are going to implement this project using the Java language.
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Add dependency of UIL Image library in build.gradle file.
Navigate to the gradle scripts and then to build.gradle(Module) level. Add below line in build.gradle file in the dependencies section.
Step 3: Add google repository in the build.gradle file of the application project if by default it is not there
All Jetpack components are available in the Google Maven repository, include them in the build.gradle file
Step 4: Add internet permission in the AndroidManifest.xml file
Navigate to the app > Manifest to open the Manifest file.
Step 5: Create a new ImageView in your activity_main.xml.
Navigate to the app > res > layout to open the activity_main.xml file. Below is the code for the activity_main.xml file.
Step 6: Initialize your ImageView and use UIL(Universal Image Loader) in the MainActivity.java file
Navigate to the app > java > your apps package name > MainActivity.java file. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Note: All drawables are present in the drawable folder. You can add the drawable in the drawable folder. To access the drawable folder. Navigate to app > res > drawables > this folder is having all your drawables.