我在我的应用程序中创建了一个 float 操作按钮,我想将其弹出,它是不可见的,并开始增长到 60dp 的大小,然后调整回 56dp 的正常大小。那怎么办?我知道如何在动画中做一个正常的淡入淡出,但不知道如何弹出。
最佳答案
我会在 res/anim 中创建一个动画文件,并使用像这样的顺序缩放动画:
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>
然后在你的 Activity 中:
Animation expandIn = AnimationUtils.loadAnimation(this, R.anim.expand_in);
actionButton.startAnimation(expandIn);
关于Android 流行动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30535304/