问题
When change from Ativity A to Activity B and viceversa I want that only Activity B to animate, but in my case Activity A also animates.(leaving a blank space in the left of the screen) Activity B animation is working well, my problem is with the animation of Activity A.(which shouldn't exists). I have set
//Activity B
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.mylayout);
//..........
}
only in Activity B. I want that Activity A never animates or disappears from the screen.
I fixed the reverse animation(change from Activity B to Activity A) in this way:
//Activity B
@Override
public void onPause(){
super.onPause();
overridePendingTransition(0, R.anim.fadeout);
}
This works good, so, now the problem is only with the change from Activity A to Activity B, I would like the same behave of Activity A(just stay, no animation).
But If I try overridePendingTransition(R.anim.fadein, 0); in onCreate(), Activity A disappears from the screen.
fadein.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p" android:toXDelta="0%p" android:duration="1000"/>
fadeout.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="0%p" android:toXDelta="100%p" android:duration="1000"/>
</set>
In the first image is what I get now, in the second image is what I want to get.
回答1:
Try this.
staystill.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%p" android:toYDelta="0%p"
android:duration="@android:integer/config_longAnimTime"
/>
来源:https://stackoverflow.com/questions/14871637/how-to-animate-just-one-activity-when-activity-change