I mave a floating action button in my app which I want to sort of pop in, where it is invisible and starts to grow to a size like 60dp and then resizes back to the normal size of 56dp. How can that be done? I know how to do a normal fade in animation, but not a pop in.
1) Create Two Different set of animations. say, popup_show. xml and popup_hide. xml and add it to your anim folder which you have to create inside res folder.
With over a million downloads, Animation Desk is one of the best animation apps for Android that you can try. It has all the things that make an animation app great—a clutter-free user interface, an adequate amount of options, and a handful of ways to export the finished animation.
I would create a animation file in res/anim and use a sequential scale animation like so:
expand_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.0"
android:fromYScale="0.0"
android:toXScale="1.1" <!--set the scale value here-->
android:toYScale="1.1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="400"/> <!--length of first animation-->
<scale
android:fromXScale="1.1" <!--From whatever scale you set in the first animation-->
android:fromYScale="1.1"
android:toXScale="1.0" <!--Back to normal size-->
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="400" <!--start 2nd animation when first one ends-->
android:duration="400"/>
</set>
Then in your activity:
Animation expandIn = AnimationUtils.loadAnimation(this, R.anim.expand_in);
actionButton.startAnimation(expandIn);
I found that my animation was much smoother than the current accepted answer when I switched it to use the Overshoot Interpolator.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/overshoot_interpolator" >
<scale
android:duration="700"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
Here is a video showing examples of the interpolators: https://www.youtube.com/watch?v=OMOJxBe9KGg
Here is where it's touched on in the Android documentation: https://developer.android.com/guide/topics/resources/animation-resource.html#View
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With