如何用动画android放大和return?

How to zoom in and return with animation android?

我一直在尝试放大视图,然后 return 回到原始大小,并像动画一样缩小。

我能做的是在一组中放大和缩小并在单击按钮时在 imageview 上对其进行动画处理,但它第一次突然减小了图像大小,然后在稍后进行了动画处理点击次数。我将不胜感激任何帮助来完成流畅的动画

我的代码

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    >
    <scale
        android:duration="1000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale=".5"
        android:toYScale=".5" >
    </scale>
    <scale
        android:duration="1000"
        android:fromXScale=".5"
        android:fromYScale=".5"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1" >
    </scale>

</set>
final Animation ani_in = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoomin_out);
imageView.startAnimation(ani_in);

动画已过时()。使用 ValueAnimator:

        final ValueAnimator anim = ValueAnimator.ofFloat(1f, 1.5f);
        anim.setDuration(1000);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                image.setScaleX((Float) animation.getAnimatedValue());
                image.setScaleY((Float) animation.getAnimatedValue());
            }
        });
        anim.setRepeatCount(1);
        anim.setRepeatMode(ValueAnimator.REVERSE);
        anim.start();

不需要使用两个比例标签,只用一个比例标签就可以完成

通过使用这两个:

android:repeatCount="infinite"
 android:repeatMode="reverse"

在你的动画文件中

<scale
        android:duration="30000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="90%"
        android:pivotY="90%"
        android:toXScale="1.5"
        android:toYScale="1.5"
        android:startOffset="1000"
        android:repeatCount="infinite"
        android:repeatMode="reverse">
    </scale>

在代码文件中

imageView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.zoomin_out));