Overriding pending transition in android

I have two activities. Activity A and Activity B.

When I launch Activity B from Activity A. I want Activity A to be static so that its positions and animations only show for Activity B. How to achieve this using overridingPendingTransition?

This below code is called from ActivityA when the button is clicked like this:

Activity A:

public void onClick(View v) {
        super.onClick(v);
         if (v.getId() == R.id.button) {
            Intent intent = new Intent();
            intent.setClass(getApplicationContext(), MyProfileActivity.class);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
        }

      

Activity A also slides with activity B. How do I stop the animation of Activity A and only animate Activity B?

slide_out_up xml looks like this:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="400"
        android:fromYDelta="0%"
        android:toYDelta="-100%" />

    <alpha
        android:duration="400"
        android:fromAlpha="1"
        android:toAlpha="0" />

</set>

      

slide_in_up:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="400"
        android:fromYDelta="100%"
        android:toYDelta="0%" />

    <alpha
        android:duration="400"
        android:fromAlpha="0"
        android:toAlpha="1" />

</set>

      

+3


source to share


2 answers


The easiest way you could go would be to pass 0 for the second parameter, not R.anim.slide_out_up. However, this usually causes Activity A to appear as a black screen behind Activity B, so as a workaround you can provide any animation that does nothing - for example. transfer from 0% to 0%.



+6


source


You must use this.

slide_in_left.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

<translate
    android:duration="400"
    android:fromXDelta="-100%"
    android:toXDelta="0%" />

<alpha
    android:duration="400"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />

</set>

      



slide_in_right.xml

 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

<translate
    android:duration="400"
    android:fromXDelta="100%"
    android:toXDelta="0%" />

<alpha
    android:duration="400"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />

</set>

      

+1


source







All Articles