Irtaza Safi Irtaza Safi - 4 years ago 105
Android Question

Simple animation for floating action button in android?

I need a very simple explanation of how I can animate this 'add to cart'

FloatingActionButton
whenever it's clicked. All I want is a smooth 'left-right' or 'down-up' movement animation.

Please look at the code below

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1"
android:background="@color/cardview_light_background">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.FloatingActionButton
android:layout_width="54dp"
android:layout_height="54dp"
android:layout_gravity="bottom|right"
android:src="@mipmap/ic_add_shopping_cart_black_24dp"
android:layout_marginBottom="40dp"
android:layout_marginRight="30dp"
app:backgroundTint="@android:color/holo_blue_light" />

</android.support.design.widget.CoordinatorLayout>
</LinearLayout>


Thank you in advance!

Answer Source

Try AndroidViewAnimations library. This library provide easy way to animate you views. There is lot of effects. For example

YoYo.with(Techniques.Tada)
.duration(700)
.playOn(findViewById(R.id.edit_area));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download