কম্পিউটার টিউটোরিয়াল

অ্যান্ড্রয়েড অ্যাপে ImageView-এ ছবি লোড ও প্রদর্শন করার পদ্ধতি


ভূমিকা

এই উদাহরণটি দেখাবে কিভাবে বাটন ক্লিক করলে ImageView-এ ড্রอয়েবল রিসোর্স থেকে ছবি লোড করে দেখাতে হয়।

ধাপ ১: নতুন প্রজেক্ট তৈরি করুন

Android Studio-তে File → New Project নির্বাচন করুন।

ধাপ ২: লেআউট ফাইল (res/layout/activity_main.xml)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" 
    xmlns:app="https://schemas.android.com/apk/res-auto" 
    xmlns:tools="https://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    tools:context=".MyAndroidAppActivity"> 
    <ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/> 
    <Button 
        android:id="@+id/btnChangeImage" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Change Image" /> 
</LinearLayout>

ধাপ ৩: মেইন এক্টিভিটি কোড (src/MyAndroidAppActivity.java)

package com.example.sample; 

import android.support.v7.app.AppCompatActivity; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.view.View; 
import android.view.View.OnClickListener; 

public class MyAndroidAppActivity extends AppCompatActivity { 
    Button button; 
    ImageView image; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        addListenerOnButton(); 
    } 

    public void addListenerOnButton() { 
        image = (ImageView) findViewById(R.id.imageView1); 
        button = (Button) findViewById(R.id.btnChangeImage); 
        
        button.setOnClickListener(new OnClickListener() { 
            @Override 
            public void onClick(View arg0) { 
                image.setImageResource(R.drawable.ic_launcher_background); 
            } 
        }); 
    } 
}

ধাপ ৪: মেনিফেস্ট ফাইল (AndroidManifest.xml)

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="https://schemas.android.com/apk/res/android" package="com.example.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=".MyAndroidAppActivity"> 
            <intent-filter> 
                <action android:name="android.intent.action.MAIN" /> 
                <category android:name="android.intent.category.LAUNCHER" /> 
            </intent-filter> 
        </activity> 
    </application> 
</manifest>

অ্যাপ্লিকেশন চালান

অ্যাপটি চালান। "Change Image" বাটনে ক্লিক করলে ImageView-এ ড্রোয়েবল রিসোর্স থেকে ছবি দেখাবে।


  1. Android-এ ImageView-এ ছবি ঘুরিয়ে দেওয়ার পদ্ধতি

  2. অ্যান্ড্রয়েডে ছবি সুস্পষ্টভাবে ঘুরানো (Smooth Image Rotation)

  3. অ্যান্ড্রয়েড অ্যাপে নোটিফিকেশন কাউন্ট কীভাবে দেখাবেন?

  4. Android-এ সার্কুলার ImageView-এ শ্যাডো এবং বর্ডার যোগ করা