imageview 的波形动画 android

Wave animation for imageview android

我正在尝试创建一个带有波浪动画的按钮。 我不想改变图片的大小,而是想做图片内外的波浪效果。

我试过这个:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<objectAnimator
    android:propertyName="scaleX"
    android:duration="2000"
    android:valueFrom="1.0"
    android:valueTo="1.3"
    android:repeatMode="reverse"
    android:repeatCount="infinite"
    android:valueType="floatType" />

<objectAnimator
    android:propertyName="scaleY"
    android:duration="2000"
    android:valueFrom="1.0"
    android:valueTo="1.3"
    android:repeatMode="reverse"
    android:repeatCount="infinite"
    android:valueType="floatType" />

但这会改变图像的大小,而不是从中发送波。

我想要这样的东西:

要创建此效果,您需要使用 AnimationSet,并向其添加两个动画,一个是调整大小动画,主要是改变视图的大小,另一个是淡入淡出动画基本上改变了这个视图的 alpha 级别。

显然它们将应用于另一个视图而不是图标视图。

代码示例:

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setDuration(1000);
 
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(sizingAnimation);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

编辑(15/09/2020):

调整动画大小:

 private Animation getResizeAnimation(Context aContext, boolean enlarge) {
    Animation resizeAnimation;
    if (enlarge) {
        resizeAnimation = AnimationUtils.loadAnimation(aContext, R.anim.scale_up_card);
    } else {
        resizeAnimation = AnimationUtils.loadAnimation(aContext, R.anim.scale_down_card);
    }
    resizeAnimation.setFillAfter(true);
    return resizeAnimation;
}

其中 scale_up_card 是:

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

scale_down_card

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

显然,对于您的情况,可能需要的动画有所不同。