首页 > 解决方案 > Android动画成功完成图

问题描述

我有一个图像视图,其中有 3 个图像

  1. green_circle - 我必须放大 -> 然后 zoom_out (在指定时间)
  2. white_tick - 我必须放大 -> 然后 zoom_out (在指定时间)
  3. green_sparkle - 放大和淡出

Imageview 正在使用图层可绘制对象设置如下 -

int[] firstImageArray = new int[]{R.drawable.ic_green_circle, R.drawable.ic_outer_sparkle, R.drawable.ic_white_tick_mark};
Drawable[] layers = new Drawable[firstImageArray.length];
for(int i = 0; i<firstImageArray.length; i++) {
    layers[i] = getResources().getDrawable(firstImageArray[i]);
}
imageView.setImageDrawable(new LayerDrawable(layers));

动画文件与此类似(用于在指定时间放大和缩小): R.anim.image_circle_zoom :

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2333"
    >

    <scale
        android:duration="233"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0" />

    <scale
        android:duration="69"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="1931"
        android:toXScale="1.18"
        android:toYScale="1.18" />

    <scale
        android:duration="165"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="2000"
        android:toXScale="0.0"
        android:toYScale="0.0" />
</set>

我必须实现类似于此link1link2的动画

我已经尝试过 AnimationSet、AnimatorSet 和 ObjectAnimator,但我无法达到预期的效果。任何帮助将不胜感激如何实现?

标签: androidxmlanimationandroid-animation

解决方案


您添加指向 Lottie 动画文件的链接。该文件可以直接包含到项目中。只需json从站点复制文件并将其放入LottieAnimationView. 这是文档和 github存储库的链接。制作此类动画的最简单方法是通过 lottie 文件。

另一种方法是使用SVG图像,图像的每个部分都应该是分开的path。然后你需要做的就是通过AnimatedVectorDrawable. 有很多关于如何像这样这样实现它的好教程


推荐阅读