Sliding Animation Between Activities Android Tutorial By Fahim khan



Animation in Android Activity

  1. Create New Android studio project, Add new Activity because we want to show Sliding Animation between these two activities.
  2. Create "anim" folder inside "res" folder
  3. Inside anim folder we are going to create our four Animation xml Files. All code is below.

left_to_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate android:fromXDelta="-100%" android:toXDelta="0%"
             android:fromYDelta="0%" android:toYDelta="0%"
             android:duration="700"/>
</set>

right_to_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate
     android:fromXDelta="0%" android:toXDelta="100%"
     android:fromYDelta="0%" android:toYDelta="0%"
     android:duration="700" />
</set>

MainActivity

In the mainActivity use this code while calling the other activity
startActivity(new Intent(getApplicationContext(),SecondActivity.class));
overridePendindTransition(R.anim.left_to_right,R.anim.right_to_left);
In onDestroy  Method use this code so it will provide animation when we pressed back button

@override
onDestroy(){

      startActivity(new Intent(getApplicationContext(),SecondActivity.class));
     overridePendindTransition(R.anim.right_to_left,R.anim.left_to_right);
}

Thats it now youre good to go for android animation

Conclusion: 

This tutorial is for target audience who just have started learning Android Programming.
code is from stackoverflow


Comments

Popular posts from this blog

HOW TO GET FREE WEB HOSTING FOR WEBSITE BY FAHIM KHAN

Git Challenge V

Demystifying Java: Your Journey to Coding