Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Android L animations for switching between activities

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.

Gmail animation

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.

like image 521
Jack Wilsdon Avatar asked Nov 09 '14 21:11

Jack Wilsdon


1 Answers

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);

like image 119
Jack Wilsdon Avatar answered Nov 15 '22 21:11

Jack Wilsdon