Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding pending transition in android

Tags:

android

I have two activities.. Activity A and Activity B.

When I start Activity B from Activity A. I want Activity A to be static to its positions and animations to show up only for Activity B. How do i achieve this using overridingPendingTransition?

This below code is called from ActivityA when button is clicked as follows :

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 to stop the animation of Activity A and enable animations of Activity B alone?

slide_out_up xml is as follows :

<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>
like image 819
Shalini Avatar asked Feb 11 '23 14:02

Shalini


2 Answers

The simplest way you could go is pass 0 for the second parameter, instead of R.anim.slide_out_up. However, this usually leads to Activity A showing up as a black screen behind Activity B, so as a workaround you can provide any animation that does nothing - e.g. translation from 0% to 0%.

like image 183
Egor Avatar answered Feb 23 '23 15:02

Egor


Need to 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>
like image 34
Piyush Avatar answered Feb 23 '23 13:02

Piyush