How to achieve right to left animation to start the activity

person shubham sharmafolder_openAndroid, Animationlocal_offer, access_time March 6, 2017

Do these modifications to your animation files:

enter.xml:

 

exit.xml:

 

You’ll have your second activity sliding in from right to the left.

For a better understadnig on how to play around with the fromXDelta and toXDelta values for the animations, here is a very basic illustration on the values:

This way you can easily understand why you add android:fromXDelta=”0%” and android:toXDelta=”-100%” for your current activity. And this is because you want it to go from 0% to the -100% position.

[EDIT]

So if you want to open ActivityB from ActivityA you do the following(let’s say you have a button):

 

Now, if you want to have the “backwards” animation of the first one, when you leave Activity B, you’ll need 2 new animation files and some code in the ActivityB’s onBackPressed method, like this:

First the animation files: left_to_right.xml:

 

right_to_left.xml:

 

And in ActivityB do the following:

 

Also if you have up navigation enabled, you’ll have to add the animation in this case as well:

You enable UP navigation like this:

 

And this is how you handle the animation in this case too:

 

 

warningComments are closed.