【发布时间】:2016-04-05 20:35:58
【问题描述】:
我正在使用自定义浮动操作菜单。我需要像这里一样在显示/隐藏菜单按钮上实现缩放动画 floating action button behaviour
有什么办法吗?
【问题讨论】:
标签: android material-design floating-action-button
我正在使用自定义浮动操作菜单。我需要像这里一样在显示/隐藏菜单按钮上实现缩放动画 floating action button behaviour
有什么办法吗?
【问题讨论】:
标签: android material-design floating-action-button
设计支持库修订版 22.2.1 将 hide() 和 show() 方法添加到 FloatingActionButton 类,因此您可以从现在开始使用它们。
FloatingActionButton mFab;
mFab.hide();
mFab.show();
您可以在其上应用您自己的动画。
欲了解更多信息check this.
有关 FAB 的更多信息,请查看official documentation.
【讨论】:
您可以将这些缩放动画用于 fab 按钮,它提供与设计 lib fab 按钮相同的效果。
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>
【讨论】:
FloatingActionButton fab = this.findViewById( ... ); Animation myAnim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale_up); fab.startAnimation(myAnim);
在您的自定义视图上加载这些动画。不要忘记将轴心点设置为 50%,将插值器设置为线性插值器。
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>
【讨论】: