Android 流行动画

标签 android button android-activity android-animation

我在我的应用程序中创建了一个 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/

相关文章:

Android - 字体(只有字母)背景颜色

android - 没有这样的属性 : variantManager

JavaScript - 5 秒后单击所有带有类名的按钮 (Twitter)

c# - 如何移动数组中的按钮并设置空的来源?

android服务 Activity 行为概念检查

android - 带有定向支持的飞溅 Activity

android - 二维码扫描仪

java - 当我单击 ListView 项目时,如何接收类对象?

Java 按钮 Action 监听器会触发其他监听器吗?

android - 从 BroadcastReceiver 关闭正在运行的应用程序