动画增加高度

Animation increase height

我现在正在做的是声波,为此我创建了一个增加高度的动画

请看这张图

所以我的问题是动画有效并且它增加了高度但是我想让它反向增长

希望你能帮助我谢谢

所以我的代码在这里

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

我不知道有什么方法可以在继续使用动画资源的同时解决您的问题。我会改用 ObjectAnimator.

以下是使用 ObjectAnimator 构建相同动画的方法:

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

您还必须在定义它的任何布局文件中向您的 View 添加一个属性。在我的例子中,我让我的观点 400dp 高,所以我添加了这个:

android:transformPivotY="400dp"

这将导致缩放动画锚定在视图的底部(因为它的枢轴等于它的高度)。