Instantly share code, notes, and snippets.

Embed
What would you like to do?
Activity transition animations like the Vine Android application. - See more at: http://blog.quent.in/index.php/2013/06/activity-transition-animations-like-the-vine-android-application/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="100%p"
android:toXScale="80%p"
android:fromYScale="100%p"
android:toYScale="80%p"
android:pivotX="50%p"
android:pivotY="50%p"
android:duration="@android:integer/config_mediumAnimTime" />
<alpha android:fromAlpha="1"
android:toAlpha="0.5"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="80%p"
android:toXScale="100%p"
android:fromYScale="80%p"
android:toYScale="100%p"
android:pivotX="50%p"
android:pivotY="50%p"
android:duration="@android:integer/config_mediumAnimTime" />
<alpha android:fromAlpha="0.5"
android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
public class AnimatedActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//opening transition animations
overridePendingTransition(R.anim.activity_open_translate,R.anim.activity_close_scale);
}
@Override
protected void onPause()
{
super.onPause();
//closing transition animations
overridePendingTransition(R.anim.activity_open_scale,R.anim.activity_close_translate);
}
}
@bgorkowy

This comment has been minimized.

bgorkowy commented Apr 11, 2014

What to do to prevent exit animation on Home button press (going to your home screen)?

@nbarnold01

This comment has been minimized.

nbarnold01 commented Jul 8, 2014

I've found that declaring the entrance and exit animations as a style in your styles.xml file work well if you want to get every activity to have the same animations and want to avoid weird side effects with the home button.

This is from a styles.xml in a stack overflow post found here http://stackoverflow.com/questions/12370793/activity-exit-animations-dont-work-as-expected-on-android-4-0:

<style name="down_up_theme" parent="Theme.rtlfr">
    <item name="android:windowAnimationStyle">@style/down_up_animation</item>
</style>

<style name="down_up_animation" parent="@android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/slide_in_top</item>
    <item name="android:activityOpenExitAnimation">@anim/hold</item>
    <item name="android:activityCloseEnterAnimation">@anim/hold</item>
    <item name="android:activityCloseExitAnimation">@anim/slide_out_bottom</item>
</style>
@snehazanzane

This comment has been minimized.

snehazanzane commented Aug 19, 2014

hi this is not work samsung Grand 2 kitkat device

@Gopinathp

This comment has been minimized.

Gopinathp commented Oct 1, 2014

@bgorkowy You can move the one line of code from onPause method to finish() method.

public void finish() {
super.finish();
overridePendingTransition(R.anim.activity_open_scale,R.anim.activity_close_translate);
}

@RobbySmet

This comment has been minimized.

RobbySmet commented Oct 16, 2014

The exit animation doesn't execute in my application, any idea what could cause this?
I have 4.4.4 on Nexus 5

@shercoder

This comment has been minimized.

shercoder commented Feb 10, 2015

@kwent Nice work! Is it okay to call overridePendingTransition from onActivityCreated and onActivityPaused of Application.ActivityLifecycleCallbacks?

@emitchel

This comment has been minimized.

emitchel commented Aug 10, 2017

I'd recommend calling overridePendingTransition on startActivity and onBackPressed (assuming you've wire up your home buttons to onBackPressed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment