How can I use some of the Android L animations for switching between activities? I can only find information about defining custom animations.
I cannot find any documentation about the following animation between the Inbox and Settings activities in the Android Developer Documentation.
I have extracted the anim files from Gmail but when using the following, the activities only slide up and down, and there is no Z movement (depth).
activity.overridePendingTransition(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_top);
You can find the anim files used here.
It looks like Gmail uses the Animation class to create animations, so I had to create my own version.
swap_in_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:startOffset="200"
android:zAdjustment="top">
<alpha
android:duration="150"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
<translate
android:duration="200"
android:fromYDelta="100.0%p"
android:toYDelta="0.0" />
</set>
swap_out_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:zAdjustment="bottom">
<scale
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="0.9"
android:toYScale="0.9" />
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.5" />
<translate
android:duration="400"
android:fromYDelta="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="100"
android:toYDelta="20.0%p" />
</set>
And the code to use it;
overridePendingTransition(R.anim.swap_in_bottom, R.anim.swap_out_bottom);
Here's how my custom animation looks (a lot smoother on the device);
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