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

অ্যান্ড্রয়েডে স্লাইড আপ/ডাউন অ্যানিমেশন সহ ভিউ শো/হাইড করার পদ্ধতি

স্লাইড অ্যানিমেশন সহ ভিউ দেখানো/লুকানো

এই উদাহরণটি দেখায় কীভাবে TranslateAnimation ব্যবহার করে ভিউকে স্লাইড আপ/ডাউন অ্যানিমেশন সহ দেখানো এবং লুকানো যায়।

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

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:layout_height="match_parent">
    <Button
        android:id="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:layout_width="150dp"
        android:text="ক্লিক করুন"
        android:layout_height="wrap_content"/>
    <LinearLayout
        android:id="@+id/view"
        android:background="#A6E1AA"
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_margin="20dp"
        android:layout_height="200dp">
        <EditText
            android:hint="ব্যবহারকারীর নাম"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <EditText
            android:hint="পাসওয়ার্ড"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</RelativeLayout>

এখানে একটি বাটন এবং একটি LinearLayout (নিচে অবস্থিত) রয়েছে। বাটনে ক্লিক করলে LinearLayout স্লাইড আপ/ডাউন হবে।

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

package com.example.andy.myapplication;

import android.os.Bundle;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.LinearLayout;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    boolean opened = false;
    LinearLayout view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        view = findViewById(R.id.view);
        view.setVisibility(View.INVISIBLE);
        
        findViewById(R.id.button).setOnClickListener(v -> {
            if (!opened) {
                // ভিউ দেখানো (স্লাইড আপ)
                view.setVisibility(View.VISIBLE);
                TranslateAnimation animate = new TranslateAnimation(
                    0, 0, view.getHeight(), 0);
                animate.setDuration(500);
                animate.setFillAfter(true);
                view.startAnimation(animate);
            } else {
                // ভিউ লুকানো (স্লাইড ডাউন)
                TranslateAnimation animate = new TranslateAnimation(
                    0, 0, 0, view.getHeight());
                animate.setDuration(500);
                animate.setFillAfter(true);
                view.startAnimation(animate);
                view.setVisibility(View.INVISIBLE);
            }
            opened = !opened;
        });
    }
}

স্লাইড আপ (দেখানোর) কোড:

TranslateAnimation animate = new TranslateAnimation(0, 0, view.getHeight(), 0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);

স্লাইড ডাউন (লুকানোর) কোড:

TranslateAnimation animate = new TranslateAnimation(0, 0, 0, view.getHeight());
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);

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

অ্যাপটি চালান। বাটনে ক্লিক করলে লগইন ফর্ম স্লাইড আপ করে উপরে আসবে। আবার ক্লিক করলে স্লাইড ডাউন করে নিচে যাবে।

  1. iCloud+ দিয়ে Hide My Email ঠিকানা তৈরি, দেখা, এবং পরিচালনা করার পদ্ধতি

  2. ওয়ার্ডে টেক্সট শো ও হাইড করার পদ্ধতি

  3. পাওয়ারপয়েন্টে প্রেজেন্টার ভিউ দিয়ে নোটস দেখার পদ্ধতি

  4. অ্যান্ড্রয়েডে ফাইল ও অ্যাপ সুরক্ষিতভাবে লুকান: ধাপে ধাপে গাইড