hide/show fab with scale animation

被刻印的时光 ゝ 提交于 2019-12-20 10:46:20

问题


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 ?


回答1:


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>



回答2:


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.




回答3:


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>


来源:https://stackoverflow.com/questions/34553755/hide-show-fab-with-scale-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!