Seamless left to right activity transition animation in Android

11,943

Change

android:toXDelta="-100%"

to

android:toXDelta="100%"

in the out animation.

Share:
11,943
Ufuk Can Bicici
Author by

Ufuk Can Bicici

Updated on June 15, 2022

Comments

  • Ufuk Can Bicici
    Ufuk Can Bicici almost 2 years

    I have two activities and I want that when the user touches a button on the first activity, the new activity slides in from the left and moves to the right while the first activity does the same, it moves to the right and slides out, so it would give an effect in which the new activity pushes the old one to the right and replaces it.

    In order to do that, I have written the following XMLs:

    In animation

    <?xml version="1.0" encoding="utf-8"?>
        <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
        android:fromXDelta="-100%"
        android:toXDelta="0"
        android:duration="1250" />
     </set>
    

    Out animation

    <?xml version="1.0" encoding="utf-8"?>
       <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
        android:fromXDelta="0"
        android:toXDelta="-100%"
        android:duration="1250" />
      </set>
    

    I call the overridePendingTransition(R.anim.anim_in,R.anim.anim_out); function in the onCreate method of the new activity. In the resulting effect, the new activity moves from the left to right correctly, but the first, older activity moves into the opposite direction; it moves to the left. I want to revert the moving direction of this first activity. How can I do that, is there a XML property which serves to this purpose?