Introduction
Inside the fade_out folder you will write alpha animation because you need to fade_out one TextView as in the following:
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android"
- android:fillAfter="true" >
- <alpha
- android:duration="1000"
- android:fromAlpha="1.0"
- android:interpolator="@android:anim/accelerate_interpolator"
- android:toAlpha="0.0" />
- </set>
Inside the fade_In folder you will write alpha animation because you need to fade_in one TextView as in the following:
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android"
- android:fillAfter="true" >
- <alpha
- android:duration="1000"
- android:fromAlpha="0.0"
- android:interpolator="@android:anim/accelerate_interpolator"
- android:toAlpha="1.0" />
- </set>
In the Java Class file, you will first create the two Animation objects, FadeIn and FadeOut. In these objects, you will load the animations fade_in and fade_out by calling the loadAnimation() method of the AniamtionUtills class.
- FadeIn = AnimationUtils.loadAnimation(getApplicationContext()R.anim.fade_in);
- FadeOut = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_out);
Step 1
Create an XML file and write this:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="#ff8769">
- <TextView android:id="@+id/txtView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Fade In Text"
- android:layout_centerInParent="true"
- android:textSize="25dp"
- android:textStyle="italic"/>
- <TextView android:id="@+id/txtView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Fade Out Text"
- android:layout_centerInParent="true"
- android:textSize="25dp"
- android:visibility="gone"
- android:textStyle="italic"/>
- <Button android:id="@+id/btnAnimation"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Start Animation"
- android:layout_marginTop="30dp"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="20dp"/>
- </RelativeLayout>



Comments
Join the conversation! Your thoughts help the community grow.