অ্যান্ড্রয়েডে Glide লাইব্রেরি ব্যবহার করে অ্যানিমেটেড GIF দেখানো
এই উদাহরণটি দেখায় কিভাবে পপুলার ইমেজ লোডিং লাইব্রেরি Glide ব্যবহার করে Android-এ অ্যানিমেটেড GIF ছবি লোড এবং প্রদর্শন করা যায়।
ধাপ ১: নতুন প্রজেক্ট তৈরি করুন এবং Glide ডিপেন্ডেন্সি যোগ করুন
Android Studio-তে File → New Project এ যান এবং একটি নতুন প্রজেক্ট তৈরি করুন।
build.gradle (Module: app) ফাইলে dependencies ব্লকে নিচের লাইনটি যোগ করুন:
dependencies {
implementation 'com.github.bumptech.glide:glide:4.16.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'
}
নোট: সর্বশেষ ভার্সন Glide GitHub-এ চেক করুন।
এরপর Sync Now ক্লিক করুন।
ধাপ ২: লেআউট XML (activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<Button
android:id="@+id/btnShowGif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="SHOW GIF"
android:textAlignment="center" />
</RelativeLayout>
ধাপ ৩: MainActivity.java
package com.app.sample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btnShowGif).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showGif();
}
});
}
private void showGif() {
ImageView imageView = findViewById(R.id.imageView);
// drawable ফোল্ডারে tenor.gif থাকতে হবে
Glide.with(this)
.asGif() // স্পষ্টভাবে GIF হিসেবে লোড করুন
.load(R.drawable.tenor)
.into(imageView);
}
}
ধাপ ৪: AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="app.com.sample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
অ্যাপটি চালান
res/drawable/ ফোল্ডারে tenor.gif নামে একটি অ্যানিমেটেড GIF ফাইল রাখুন। ডিভাইস সংযুক্ত করে Run ক্লিক করুন। SHOW GIF বাটনে ক্লিক করলে GIF অ্যানিমেশন প্লে হবে।
