Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seamless left to right activity transition animation in Android

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?

like image 319
Ufuk Can Bicici Avatar asked Mar 18 '13 15:03

Ufuk Can Bicici


1 Answers

Change

android:toXDelta="-100%"

to

android:toXDelta="100%"

in the out animation.

like image 154
minipif Avatar answered Sep 30 '22 16:09

minipif