I have two activites A and B. In A, I call B:
Intent intent = new Intent(this, ActivityB.class);
this.startActivity(intent);
overridePendingTransition(R.anim.activity_animation_right_to_left, R.anim.activity_animation_zoom_in);
However, only R.anim.activity_animation_right_to_left
works. The other animation is not applied. Also, when coming back from B to A:
finish();
overridePendingTransition(R.anim.activity_animation_zoom_out, R.anim.activity_animation_left_to_right);
onlR.anim.activity_animation_left_to_right
works. I am sure that other animation works like a charm in other situation (there is nothing wrong with them). I even use that the same transition when calling external activities such as opening a browser window. The animation works. Only for my Activity B, it doesn't work.
Edit: here is the animations XMLs:
R.anim.activity_animation_right_to_left
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="100%"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="0%" />
R.anim.activity_animation_left_to_right
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="100%" />
R.anim.activity_animation_zoom_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="500"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:toXScale="0.85"
android:toYScale="0.85" />
</set>
I finally fixed it. I checked my Manifest file and I found that I set the theme Theme.Translucent.NoTitleBar
to every activity I create. Once, I removed the theme from all of them, the animation works like a charm. Still, do not know exactly why this theme affects the animation.
Some example of animations maybe it can helps
anim_left :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="-100%"
android:fromYDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="0"
android:toYDelta="0" />
</set>
anim_right :
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="100%"
android:toYDelta="0" />
</set>
anim_back_left :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="-100%"
android:toYDelta="0" />
</set>
anim_back_right:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="100%"
android:fromYDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="0"
android:toYDelta="0" />
</set>
For fade in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<alpha
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0" >
</alpha>
</set>
fade_out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" >
</alpha>
</set>
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:resizeable="true"
android:anyDensity="true">
</supports-screens>
(try adding this to your manifest)
I changed the animation zoom-in, zoom-out, and it works well in my device(Nexus 4).
A->B
overridePendingTransition(R.anim.activity_animation_zoom_in, R.anim.activity_animation_right_to_left);
B->A
overridePendingTransition(R.anim.activity_animation_left_to_right, R.anim.activity_animation_zoom_out);
R.anim.activity_animation_zoom_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="500"
android:fillAfter="false"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
R.anim.activity_animation_zoom_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="300"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:toXScale="0.5"
android:toYScale="0.5" />
</set>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With