Android 安卓流行动画

Android 安卓流行动画,android,button,android-activity,android-animation,Android,Button,Android Activity,Android Animation,我在我的应用程序中有一个浮动的动作按钮,我想把它弹出,在那里它是不可见的,开始增长到像60dp的大小,然后重新调整到56dp的正常大小。如何做到这一点?我知道如何进行普通淡入动画,但不知道如何进行弹出动画。我会在res/anim中创建一个动画文件,并使用顺序缩放动画,如下所示: 展开_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/r

我在我的应用程序中有一个浮动的动作按钮,我想把它弹出,在那里它是不可见的,开始增长到像60dp的大小,然后重新调整到56dp的正常大小。如何做到这一点?我知道如何进行普通淡入动画,但不知道如何进行弹出动画。

我会在res/anim中创建一个动画文件,并使用顺序缩放动画,如下所示:

展开_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>

当我切换到使用超调插值器时,我发现我的动画比当前接受的答案平滑得多

<?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>

以下是显示插值器示例的视频:


以下是Android文档中涉及的内容:

我接受了原始答案,但添加了额外的动画层,以提供更好的流行效果

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>
在此处输入代码

非常感谢。我必须先使用可见性隐藏按钮吗?如果要将第一个动画比例设置为从0.0开始,则不必隐藏按钮。因此,它工作正常,唯一的问题是它从一个角开始展开。相反,is应该从其中心扩展。我怎样才能解决这个问题呢?非常感谢:)接受了答案我发现当我将“收缩”部分改为0.9而不是1.0时,这个动画更流畅。我不知道为什么。添加@AhmedW的建议没有帮助。
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>