Glide Image Loader Library in Android Apps

Glide is an Android library that displays images from URLs. It also takes care of caching and keeping memory on images. It provides animated GIF support and handles load /caching. 

Glide is required in every project when you need to load single or multiple images on an application. 

Step-By-Step Implementation


Step 1: Create a new project in Android or you can use an already created project.  

Step 2: Add dependency of glide in build.gradle file on Gradle scripts>Build.gradle app module and add the below dependencies.

implementation (libs.glide)

annotationProcessor (libs.compiler)

Step 3: Add permission to the internet in app> Androidmanifest.xml file and below code.

<uses-permission android:name="android.permission.INTERNET" />




 

Step 4: Create an activity_main.xml file in the layout folder. 

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

 

// Textview set title Glide image loader demo

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_marginTop="60dp"

android:text="Glide Image Loader demo"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

 

//Imageview logo

<ImageView

android:id="@+id/glideimage"

android:layout_width="200dp"

android:layout_height="200dp"

android:layout_marginTop="108dp"

android:src="@drawable/company_logo"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView" />

 

//image loader 

<ImageView

android:id="@+id/glideimageloaderr"

android:layout_width="55dp"

android:layout_height="48dp"

android:layout_margin="15dp"

android:src="@drawable/company_logo"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Step 5: Create a MainActivity.java file and put the below code.

import android.os.Bundle;

import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;

public class MainActivity extends AppCompatActivity {

private ImageView glideimage;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

glideimage = findViewById(R.id.glideimage);

 

//Glide image load 

Glide.with(this)

.load("http://via.placeholder.com/300.png")

.placeholder(R.drawable.company_logo)

.into(glideimage);}}

 

Step 6: Output of glide image.


Happy Coding!

365Bloggy May 9, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive