In android OS 2.1 or later I think you can use the OverridePendingTransition() method to provide the kind of transition between activities animations you are looking for.
Firstly, define a couple of animation resources in /res/anim/. Here is one that is named right_slide_out.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500"
/>
</set>
An another called right_slide_in.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="700"
/>
</set>
Then, when you are starting the new activity, use the OverridePendingTransition method as in:
startActivity(intent);
overridePendingTransition (R.anim.right_slide_in, R.anim.right_slide_out);
That should handle the transition animations for starting the activity.
For the reverse, when that activity finishes and youre coming back to the original one, it's a bit more foggy.
If you have some UI control that ends that activity and calls Activity.finish(), then you can just add the overridePendingTransition() right after that.
To handle the case where the user ends the activity by pressing the back button, use something like the following:
@Override
public void onBackPressed()
{
this.finish();
overridePendingTransition (R.anim.right_slide_in, R.anim.right_slide_out);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…