如何放大动画android并返回?

问题描述 投票:0回答:1

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

我能够做的是将放大和缩小放进一个集合中,并在单击按钮时在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);
android android-animation
1个回答
0
投票

动画已过时(Animation vs Animator)。使用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();

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.