HowTo: Getting Started With Glide

Glide is one of the most used image loading library in the world of android applications. It is well tested, provides a number of features and is fast and optimized.

Step 1:

To get started add Glide to your project dependency. Add the following lines to build.gradle file. Please check the latest version here and make the necessary adjustments.

dependencies {
    // your app's other dependencies
    implementation 'com.github.bumptech.glide:glide:4.5.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
}

Step 2:

Give internet permissions to your application if the image is on a remote location. Add the following lines to AndroidManifest.xml file.

<manifest
    ... >
    // this line
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:label="@string/app_name"
        android:name=".MyApplication">
        ...
    </application>
    ...
</manifest>

Step 3:

Add the following lines to the layout.xml file.

<ImageView
    android:id="@+id/my_image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher"
/>

Step 4:

Finally, add the following lines to the Activity.java file

ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
GlideApp.with(context)
        .load(url)
        .placeholder(R.drawable.placeholder)
        .into(imageView);

Placeholder is the image that will be displayed while the requested image is being loaded. Placeholder is optional and can be excluded.

Step 5:

That is all, now build and run the application.

If there are any questions let me know in the comments below. Check out the HowTo for Picasso and Fresco as well.

Show Comments