Skip to content

Instantly share code, notes, and snippets.

@sheharyarn
Last active March 16, 2021 08:04
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sheharyarn/0619bf643be5f0dcec8a to your computer and use it in GitHub Desktop.
Save sheharyarn/0619bf643be5f0dcec8a to your computer and use it in GitHub Desktop.
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
Copy link

Great!!! Excelent animation.

@Henriquedn
Copy link

Awesome

@simplekjl
Copy link

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
Copy link

awesome

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