我在我的应用程序中有一个浮动的操作按钮,我想要弹出它,它是看不见的,开始增长到像60dp的大小,然后重新调整到56dp的正常大小。如何做到这一点?我知道如何在动画中做一个普通的淡入淡出,但不会弹出。
发布于 2015-05-30 01:28:37
我将在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>
然后在你的活动中:
Animation expandIn = AnimationUtils.loadAnimation(this, R.anim.expand_in);
actionButton.startAnimation(expandIn);
发布于 2016-09-07 06:30:06
当我切换到使用过冲内插器时,我发现我的动画比目前接受的答案要流畅得多。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/overshoot_interpolator" >
<scale
android:duration="700"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
以下是一段视频,展示了插值器的示例:https://www.youtube.com/watch?v=OMOJxBe9KGg
这里是安卓文档中涉及到的地方:https://developer.android.com/guide/topics/resources/animation-resource.html#View
发布于 2018-09-26 21:55:22
我采用了最初的答案,但添加了额外的一层动画,以获得更好的流行效果。
enter code here
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="100"
android:fromXScale="0.0"
android:fromYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
<scale
android:duration="100"
android:fromXScale="1.2"
android:fromYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="100"
android:toXScale="0.8"
android:toYScale="0.8" />
<scale
android:duration="100"
android:fromXScale="0.8"
android:fromYScale="0.8"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="100"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
https://stackoverflow.com/questions/30535304
复制相似问题