यह उदाहरण Android में TextView पर स्लाइड डाउन एनिमेशन दिखाने के बारे में है।
स्लाइड डाउन एनिमेशन का उदाहरण
चरण 1 - नया प्रोजेक्ट बनाएं
Android Studio में एक नया प्रोजेक्ट बनाएं: File → New Project पर जाएं और आवश्यक विवरण भरें।
चरण 2 - लेआउट XML में कोड जोड़ें
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>
उपरोक्त कोड में, TextView विशेष स्थिति तक स्लाइड डाउन करेगा।
चरण 3 - MainActivity.java में कोड जोड़ें
src/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("How to show Slide down to show textview animation");
Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
view.startAnimation(anim);
}
}
उपरोक्त कोड में, हमने slide_in_top एनिमेशन ली है, इसलिए 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>
ऐप चलाएं
अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें और ऐप चलाएं। परिणाम में, TextView स्लाइड डाउन होकर दिखाई देगा।