简体   繁体   中英

Grow Animation for Floating Action Button

What I Have

I have a Floating Action Button on the bottom of the screen.

What I Want

I want to animate the view when the activity resumes. The animation would grow the FAB from size 0 to fill size, starting from the center and growing in all directions till it finally reaches its full size.

This is just like we see in some of the Material Designed apps.

I got the solution myself actually. It was quite simple.

I created this animation in XMl and saved it in "anim".

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">

    <scale
        android:duration="250"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="500"
        android:toXScale="1.0"
        android:toYScale="1.0" />
</set>

After that its just loading and playing the animation on the view,

Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_grow);
        start.startAnimation(animation);

That's it. You are done and good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM