TextView-এ টেক্সট অ্যানিমেশন ট্রানজিশন
এই উদাহরণটি দেখায় কীভাবে একটি TextView-এর টেক্সট অ্যানিমেশন সহ অন্য টেক্সটে পরিবর্তন করা যায়।
ধাপ ১: নতুন প্রজেক্ট তৈরি করুন
Android Studio-তে File → New Project-এ যান এবং প্রজেক্ট তৈরি করুন।
ধাপ ২: লেআউট ফাইলে কোড যোগ করুন
res/layout/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:gravity="center"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text"
android:textSize="30dp"
android:textAlignment="center"
android:layout_width="match_parent"
android:textColor="#FF4500"
android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout>
<Button
android:id="@+id/animate"
android:text="অ্যানিমেটেড বাটন"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
ধাপ ৩: MainActivity.java-তে কোড যোগ করুন
package com.example.andy.myapplication;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView view = findViewById(R.id.text);
final LinearLayout parent = findViewById(R.id.parent);
view.setText("১+২");
Button animate = findViewById(R.id.animate);
animate.setOnClickListener(v -> {
Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
slideUp.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
view.setText("৩"); // অ্যানিমেশন শেষে টেক্সট পরিবর্তন
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
parent.startAnimation(slideUp);
});
}
}
ধাপ ৪: anim/slide_up.xml তৈরি করুন
res/anim/slide_up.xml ফাইলটি তৈরি করুন (স্লাইড আপ অ্যানিমেশন):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="https://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromYDelta="0%"
android:toYDelta="-100%"/>
</set>
অ্যাপ্লিকেশন চালান
অ্যাপটি চালান। প্রাথমিকভাবে "১+২" দেখাবে। "অ্যানিমেটেড বাটন"-এ ক্লিক করলে স্লাইড আপ অ্যানিমেশন হবে এবং শেষে "৩" দেখাবে।