Android动画获得成功的完整图像

时间:2019-06-23 09:30:23

标签: android xml animation android-animation

我有一个imageview,其中有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,但无法达到预期的效果。任何帮助将不胜感激如何实现?

1 个答案:

答案 0 :(得分:0)

您添加了指向Lottie动画文件的链接。该文件可以直接包含在项目中。只需从站点复制json文件并将其放入LottieAnimationView。这是docs和github repository的链接。制作此类动画的最简单方法是通过抽奖文件。

另一种方法是使用SVG图像,其中图像的每个部分都应分开path。然后,您需要做的就是通过AnimatedVectorDrawable为路径设置动画。关于如何实现它,有很多不错的教程,例如thisthis