Wave animation for imageview android

后端 未结 1 461
别那么骄傲
别那么骄傲 2021-01-01 07:41

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 th

相关标签:
1条回答
  • 2021-01-01 08:30

    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 they 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);
    

    EDITED (15/09/2020):

    Resizing Animation:

     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;
    }
    

    Where scale_up_card is:

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

    And 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>
    

    Obviously, for you case maybe the needed animations are different.

    0 讨论(0)
提交回复
热议问题