এই উদাহরণটি অ্যান্ড্রয়েডে স্মুথ ইমেজ রোটেশন বাস্তবায়নের পদ্ধতি প্রদর্শন করে।
ধাপ ১: নতুন প্রজেক্ট তৈরি করুন
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"
android:id = "@+id/parent"
xmlns:tools = "https://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = ".MainActivity"
android:gravity = "center"
android:orientation = "vertical">
<TextView
android:id = "@+id/text"
android:textSize = "18sp"
android:textAlignment = "center"
android:text = "rotate image"
android:layout_width = "match_parent"
android:layout_height = "wrap_content" />
<ImageView
android:id = "@+id/rotateImage"
android:layout_width = "match_parent"
android:layout_marginTop = "10dp"
android:layout_height = "wrap_content"
android:src = "@mipmap/ic_launcher"
android:layerType = "software" />
</LinearLayout>
উপরোক্ত কোডে, আমরা একটি TextView এবং ImageView নেওয়া হয়েছে। TextView-এ ক্লিক করলে, ইমেজটি ঘড়ির কাঁটা বাম দিকে রোটেট হবে।
ধাপ ৩: src/MainActivity.java-এ কোড যোগ করুন
package com.example.andy.myapplication;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int view = R.layout.activity_main;
TextView text;
ImageView image;
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(view);
text = findViewById(R.id.text);
image = findViewById(R.id.rotateImage);
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RotateAnimation rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(5000);
rotate.setInterpolator(new LinearInterpolator());
image.startAnimation(rotate);
}
});
}
}
উপরোক্ত কোডে, আমরা RotateAnimation ক্লাস ব্যবহার করেছি। এটি অ্যান্ড্রয়েডে একটি পূর্বনির্ধারিত ক্লাস। ইমেজ রোটেট করতে নিচের কোড ব্যবহার করুন:
RotateAnimation rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(5000); rotate.setInterpolator(new LinearInterpolator()); image.startAnimation(rotate);
আপনার অ্যাপ্লিকেশন চালানোর চেষ্টা করুন। আমি ধরে নিচ্ছি আপনার আসল Android মোবাইল ডিভাইস কম্পিউটারের সাথে সংযুক্ত আছে। Android Studio থেকে অ্যাপ চালাতে, আপনার প্রজেক্টের একটি এক্টিভিটি ফাইল খুলুন এবং টুলবার থেকে Run আইকনে ক্লিক করুন। আপনার মোবাইল ডিভাইস নির্বাচন করুন এবং তারপর আপনার মোবাইল ডিভাইস চেক করুন যা আপনার ডিফল্ট স্ক্রিন প্রদর্শন করবে।

উপরোক্ত কোডে, এটি প্রাথমিক স্ক্রিন দেখায় যখন ব্যবহারকারী TextView-এ ক্লিক করে, এটি নিচের মত ইমেজ রোটেট করবে:
