Beginner
Beginner

Reputation: 4153

Animation increase height

What I'm doing now is a sound wave and to do it I have created an animation that increase the height

please see this picture

enter image description here

so my problem is that the animation works and it increase the height however I wanted to make it reverse grow

Hope you can help me thank you

So my code is here

<scale
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXScale="1.0"
    android:toXScale="1.0"
    android:fromYScale="1.0"
    android:toYScale="0.5"
    android:duration="2000"
    android:fillAfter="false"
    android:repeatMode="reverse"
    android:repeatCount="infinite"/>

Animation animation = AnimationUtils.loadAnimation(context, R.anim.sound_wave);
view.setAnimation(animation);
view.animate();
animation.start();

Upvotes: 0

Views: 746

Answers (1)

Ben P.
Ben P.

Reputation: 54194

I do not know of a way to solve your problem while continuing to use an animation resource. I would instead use ObjectAnimator.

Here's how to build your same animation using ObjectAnimator:

ObjectAnimator anim = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.5f);
anim.setDuration(2000);
anim.setRepeatMode(ValueAnimator.REVERSE);
anim.setRepeatCount(ValueAnimator.INFINITE);
anim.start();

You also have to add an attribute to your View in whatever layout file defines it. In my case, I made my view 400dp tall, so I added this:

android:transformPivotY="400dp"

This will cause the scale animation to be anchored at the bottom of the view (since its pivot is equal to its height).

enter image description here enter image description here

Upvotes: 1

Related Questions