重复脉冲动画



我正在尝试在ImageView中创建无限脉冲效果。但是,如何保持偏移呢?

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5"/>
<scale
    android:duration="700"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="700"
    android:toXScale="2"
    android:toYScale="2"/>
</set>

这将使您的(图像)视图反复脉动到其大小的 1.2 和后退。

ImageView iv = (ImageView) findViewById(R.id.my_imageview);
ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(
                    iv,
                    PropertyValuesHolder.ofFloat("scaleX", 1.2f),
                    PropertyValuesHolder.ofFloat("scaleY", 1.2f));
scaleDown.setDuration(310);
scaleDown.setRepeatCount(ObjectAnimator.INFINITE);
scaleDown.setRepeatMode(ObjectAnimator.REVERSE);
scaleDown.start();
您可以

为集合中的每个动画设置startOffset值。

如果要

创建无限动画,最好的方法是创建自定义视图并在onDraw中创建动画。例如:如何在画布上为路径设置动画 - android

实际上,您也可以使用SurfaceView制作动画。

最新更新