2017-10-05 67 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