Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Android

Android में एक TextView से दूसरे में टेक्स्ट एनिमेट कैसे करें?

यह उदाहरण एक TextView से दूसरे में टेक्स्ट एनिमेट करने के बारे में है।

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">
    <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="Animated button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</RelativeLayout>

उपरोक्त कोड में, हमने TextView और बटन लिया है। जब उपयोगकर्ता बटन पर क्लिक करता है, तो TextView अपडेट होगा।

चरण 3 - MainActivity.java में कोड जोड़ें

src/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("1+2");
        
        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("3");
                }
                
                @Override
                public void onAnimationRepeat(Animation animation) { }
            });
            parent.startAnimation(slideUp);
        });
    }
}

res/anim/slide_up.xml में स्लाइड अप एनिमेशन परिभाषित करें।

ऐप चलाएं

अपने Android डिवाइस को कंप्यूटर से कनेक्ट करें और ऐप चलाएं। बटन पर क्लिक करने पर, TextView "1+2" से "3" में एनिमेशन के साथ अपडेट होगा।

  1. एंड्रॉइड में एक एक्टिविटी से दूसरी एक्टिविटी में इमेज कैसे पास करें एंड्रॉइड में एक एक्टिविटी से दूसरी एक्टिविटी में इमेज कैसे पास करें

    Intent के माध्यम से इमेज रिसोर्स ID या बिटमैप पास करना एंड्रॉइड में एक एक्टिविटी से दूसरी में इमेज पास करने के दो मुख्य तरीके हैं: रिसोर्स ID (इंट/ड्रॉएबल रेफरेंस) पास करना (कुशल, केवल ऐप-इंटरनल इमेज के लिए) या बिटमैप/बाइट ऐरे पास करना (किसी भी इमेज के लिए, लेकिन मेमोरी-इंटेंसिव)। चरण 1: नया प्रोजे

  1. Android में एक Fragment से दूसरे Fragment में डेटा कैसे भेजें? Android में एक Fragment से दूसरे Fragment में डेटा कैसे भेजें?

    परिचय यह ट्यूटोरियल दर्शाता है कि Android में Fragment के बीच डेटा कैसे पास करें। हम ViewPager और TabLayout का उपयोग करके दो फ्रैगमेंट्स बनाएंगे और इंटरफेस के माध्यम से डेटा ट्रांसफर करेंगे। आवश्यक चरण चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project चुनें। चरण 2: मुख्य लेआउट (res

  1. Android TextView में टेक्स्ट को जस्टिफाई कैसे करें? Android TextView में टेक्स्ट को जस्टिफाई कैसे करें?

    यह उदाहरण दर्शाता है कि Android में TextView में टेक्स्ट को जस्टिफाई (दोनों किनारों पर अलाइन) कैसे किया जाता है। समस्या Android का स्टैंडर्ड TextView android:gravity=center_horizontal या left|right से जस्टिफिकेशन सपोर्ट नहीं करता। API 26 (Android 8.0) से android:justificationMode=inter_word उपलब्ध