2017-10-05 66 views
0

我现在正在做的是一种声波,并做到这一点我已经创建了一个动画增加高度动画提升高度

请看到这张照片

enter image description 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(); 

回答

1

我不知道的方式来解决问题,同时继续使用动画资源。我会改用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" 

这将导致规模动画在视图的底部被锚固(因为其枢轴等于其高度)。

enter image description here enter image description here

+0

谢谢主席先生。 这正是我所需要的。 – Beginner