26

I'm using custom floatingactionmenu. I need to implement scale animation on show/hide menu button like here floating action button behaviour

Is there any way to do this ?

JosephM
  • 2,935
  • 4
  • 18
  • 28
  • 3
    Use the fab.show() and fab.hide() methods provided by the design lib. Also you might want to check [this](http://stackoverflow.com/questions/30937028/how-to-animate-floatingactionbutton-like-in-google-app-for-android) – Skynet Jan 01 '16 at 05:33
  • its not android fab library its custom fab menu [here](https://github.com/Clans/FloatingActionButton) – JosephM Jan 01 '16 at 05:57
  • Why do you want to use a library when the framework provides this control for you? – Skynet Jan 01 '16 at 06:19
  • http://stackoverflow.com/a/30953215/1318946 – Pratik Butani Jan 01 '16 at 06:49

3 Answers3

82

The design support library revision 22.2.1 added the hide() and show() methods to the FloatingActionButton class, so you can use these from now on.

FloatingActionButton mFab;
mFab.hide();
mFab.show();

You can apply your own animation on it. For more info check this.
And for more information about FAB, check the official documentation.

Antoine Draune
  • 323
  • 1
  • 3
  • 12
Anuj Sharma
  • 4,294
  • 2
  • 37
  • 53
27

You can use these scale animations for fab button, it gives same effect like design lib fab button.

scale_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <scale
        android:duration="100"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="85%"
        android:pivotY="85%"
        android:toXScale="1.0"
        android:toYScale="1.0" />
</set>

scale_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <scale
        android:duration="100"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="85%"
        android:pivotY="85%"
        android:toXScale="0"
        android:toYScale="0" />
</set>
Max
  • 5,733
  • 4
  • 30
  • 44
  • 11
    Where do i put this, how do i apply it? – Jemar Jones Nov 30 '16 at 19:48
  • 3
    Like Anuj said: `FloatingActionButton fab = this.findViewById( ... ); Animation myAnim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale_up); fab.startAnimation(myAnim);` – adrianoBP May 01 '18 at 18:23
8

Load these animation on your custom view. Don't forget to set pivot point to 50% and interpolator to linear interpolator.

scale_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <scale
        android:duration="100"
        android:fromXScale="0"
        android:fromYScale="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0" />
</set>

scale_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <scale
        android:duration="100"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0"
        android:toYScale="0" />
</set>
CodingRat
  • 1,934
  • 3
  • 23
  • 43