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

অ্যান্ড্রয়েডে TextView-এ স্লাইড ডাউন অ্যানিমেশন দেখানোর পদ্ধতি

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">
    <TextView
        android:id="@+id/text"
        android:textSize="20dp"
        android:textAlignment="center"
        android:layout_width="match_parent"
        android:textColor="#FF4500"
        android:layout_height="wrap_content"
        android:singleLine="true" />
</RelativeLayout>

ধাপ ৩: MainActivity.java-তে কোড যোগ করুন

package com.example.andy.myapplication;

import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
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);
        
        TextView view = findViewById(R.id.text);
        view.setText("স্লাইড ডাউন অ্যানিমেশন সহ টেক্সটভিউ");
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
        view.startAnimation(anim);
    }
}

ধাপ ৪: anim/slide_in_top.xml তৈরি করুন

res/anim/slide_in_top.xml ফাইলটি তৈরি করুন:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="https://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:repeatCount="100">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="-100%"
        android:toYDelta="0%" />
    <alpha
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

এই অ্যানিমেশনটি:

  • Y-অক্ষে -100% (স্ক্রিনের উপরের বাইরে) থেকে 0% (নор্মাল পজিশন) এ আনে
  • অ্যালফা ০.০ (অদৃশ্য) থেকে ১.০ (দৃশ্যমান) করে ফেড ইন করে
  • android:fillAfter="true" অ্যানিমেশন শেষে ফাইনাল স্টেট রাখে

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

অ্যাপটি চালান। TextView স্ক্রিনের উপর থেকে স্লাইড ডাউন করে নিজের স্থানে আসবে সাথে সাথে ফেড ইন হবে।

  1. এন্ড্রয়েডে অ্যাক্টিভিটি রিস্টার্ট করার পদ্ধতি

  2. অ্যান্ড্রয়েডে ButterKnife লাইব্রেরি ব্যবহারের পদ্ধতি

  3. অ্যান্ড্রয়েডে JSON পার্স করার সহজ পদ্ধতি

  4. Android-এ TextView-এ টেক্সট জাস্টিফাই (Justify) করার পদ্ধতি