问题
What I am trying to achieve is : start a new activity with a transition animation for the exiting activity only.
I would like to slide up the current activity, where the new activity will be behind the current one.
Here is the slide up animation : R.layout.slide_up
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="0%"
android:toYDelta="100%" />
</set>
Here is how I am applying the activity animation transition :
overridePendingTransition ( 0 , R.anim.slide_up );
I am using 0 for the entering activity since I do not want any animation for the new activity, and it is not working (the animation is not performed). If I use an animation for entering activity too, it works (both animations are performed), like such :
overridePendingTransition ( R.anim.slide_out , R.anim.slide_up );
where R.anim.slide_out :
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="100%"
android:toYDelta="0%" />
</set>
Any ideas ?
I am working on Android 4.1.2 and Android 4.0.4
回答1:
Alter your exit animation so that it renders over top of the entering activity.
R.anim.slide_up
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:zAdjustment="top">
<translate
android:duration="1000"
android:fromYDelta="0%"
android:toYDelta="100%" />
</set>
Then you can do what you were originally doing to set the animation.
overridePendingTransition ( 0 , R.anim.slide_up );
回答2:
I have exactly the same transition and such animation works for me:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromYDelta="0%" android:toYDelta="100%" android:zAdjustment="top"
android:duration="300" />
回答3:
Call the below method after startActivity method.
overridePendingTransition(0,0);
This will override the default animation and do no animation. You can also give some custom animation if you like
overridePendingTransition(R.anim.animation1,R.anim.animation2);
回答4:
Wherever you are calling the intent to start the Activity, you need to modify the intent.
ActivityOptions options =
ActivityOptions.makeSceneTransitionAnimation(AlbumListActivity.this);
startActivity(intent, options.toBundle());
If you have any dedicated method to setupTransitions()
You can put the next two lines of code there, Else you may put them in onCreate()
getWindow().setEnterTransition(new Slide(Gravity.RIGHT).setDuration(800));
Gravity.RIGHT is what determines the direction from which you want to start your next Activity. setDuration()
method is optional, for smoother Transition I used it, You don't have to.
Explore more by playing around with different Gravity and setDuration Properties.
来源:https://stackoverflow.com/questions/15090451/android-activity-transition-animation