![]() |
VOOZH | about |
Fresco is one of the famous image loading libraries from URLs in Android. It is a powerful library for displaying and managing images from URLs. This library can load images from Users' devices, servers, and other local sources. The most important feature of this library is to show a placeholder image when the image from the URL takes so much time to load. Along with this, we can use an Error image when the image is not being displayed due to any issue. To save data and CPU this library uses three levels of cache out of which two are in memory and one is in internal storage. You can check the official documentation of Fresco.
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Select Java/Kotlin as the programming language.
Navigate to gradle scripts and then to build.gradle.kts(Module) level. Add below line in build.gradle file in the dependencies section.
implementation ("com.facebook.fresco:fresco:3.6.0")and, add the google repository in the settings.gradle.kts file of the application project, if it is not there by default.
repositories {
google()
mavenCentral()
}
Navigate to the app > Manifest to open the Manifest file.
<uses-permission android:name="android.permission.INTERNET" />Navigate to the app > res > layout to open the activity_main.xml file. Below is the code for the activity_main.xml file.
activity_main.xml:
Navigate to the app > java > {package name} > MainActivity.kt/MainActivity.java file. Below is the code for the MainActivity file in both Java and Kotlin. Comments are added inside the code to understand the code in more detail.
MainActivity File:
Note: In case you are using Android Studio 4 you may face this error (NDK at ~/Library/Android/sdk/ndk-bundle did not have a source.properties file) during building the project. Please refer to this for fixing the error.