How to animate just one Activity when Activity change?

痞子三分冷 提交于 2020-01-01 19:36:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!