Wave animation for imageview android

2019-02-11 09:43发布

问题:

I am trying to create a button with wave animation. I do not want to change the size of the image, but to do effect of waves from the picture and outside.

I tried this:

<?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" />

But this changes the size of the image instead of sending a wave from it.

I want something like this:

回答1:

To create this effect you will need to use AnimationSet, And add to it two animations, one animation would be resizing animation, basically changing the size of the view, the other animation would be a fading animation basically changing the alpha level of this view.

obviously the would be applied to another view and not the icon view.

Code sample:

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setDuration(1000);

AnimationSet animation = new AnimationSet(true);
animation.addAnimation(sizingAnimation);
animation.addAnimation(fadeOut);
this.setAnimation(animation);