Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swing Animations for CardViews in Android

SwingUp Animations for Android

I use these snippets to implement Google Now Card appear-animations on Android. Add these two files to your res/anim/ folder and add a swing_anim_time integer to your values:

<!-- res/values/strings.xml -->
<integer name="swing_anim_time">750</integer>

Implement it like this in your code (or however you feel like doing it 😏):

Animation animation = AnimationUtils.loadAnimation(someContext, R.anim.swing_up_left);
yourView.startAnimation(animation);
<?xml version="1.0"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:duration="@integer/swing_anim_time"
android:fromYDelta="100%p"
android:toYDelta="0"/>
<alpha
android:duration="@integer/swing_anim_time"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
<rotate
android:duration="@integer/swing_anim_time"
android:fromDegrees="25"
android:pivotX="0"
android:pivotY="0"
android:toDegrees="0"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate
android:duration="@integer/swing_anim_time"
android:fromYDelta="100%p"
android:toYDelta="0"/>
<alpha
android:duration="@integer/swing_anim_time"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
<rotate
android:duration="@integer/swing_anim_time"
android:fromDegrees="-25"
android:pivotX="100%"
android:pivotY="0"
android:toDegrees="0"/>
</set>
@nicolasvalentini

This comment has been minimized.

Copy link

@nicolasvalentini nicolasvalentini commented Sep 28, 2016

Great!!! Excelent animation.

@Henriquedn

This comment has been minimized.

Copy link

@Henriquedn Henriquedn commented Mar 23, 2017

Awesome

@simplekjl

This comment has been minimized.

Copy link

@simplekjl simplekjl commented Mar 12, 2019

wow, this is awesome! Do you have any suggestion for card views for collapse and expand them? I have found some information but seems likes there has to be an easier way now.

Thanks for sharing!

@harshabhadra

This comment has been minimized.

Copy link

@harshabhadra harshabhadra commented Oct 18, 2019

awesome

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