2016-07-25 65 views
0

我想添加動畫多個視圖,說4個不同的圖像視圖,所以我如何啓動這些項目的動畫。流程應該是動畫從1個項目開始,當它完成動畫時,應該從第2個項目開始,當完成時它應該從第3個項目開始。多個動畫android

+0

我試圖製作兩個imageview,並在點擊按鈕的第一個項目上開始動畫。我已經使用動畫偵聽器來檢測開始和結束動畫事件,以便當第一個動畫結束時,我清除第一個動畫並增加整數變量的值並檢查位置== 1,然後它應該在另一個對象上開始動畫。這適用於2個對象,但不超過這個。 –

+0

@android_beginner所以你想要做兩個imageviews或一個imageview – eLemEnt

回答

1

您需要使用動畫。動畫監聽器界面來跟蹤或監視動畫。此偵聽器包含三種方法: 1. onAnimationStart():當動畫啓動時調用此方法。 2. onAnimationEnd():當動畫結束時調用此方法。 3. onAnimationRepeat():當動畫重複時調用此方法。

創建Animation.AnimationListener如下圖所示:現在

Animation.AnimationListener animationListener = new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 
    }; 

,以監控所有的動畫,您需要創建單獨的實例Animation.AnimationListener接口,每個動畫的。在每個界面的onAnimationEnd()方法中,您需要開始下一個動畫。例如,在第一個ImageView的Animation.AnimationListener的onAnimationEnd()方法中,開始第二個動畫ImageView

+0

你的意思是說我需要製作多個動畫監聽器? –

+0

是的,您需要爲每個動畫創建單獨的AnimationListener。 –

+0

好的,謝謝,我只是想知道如果沒有多個動畫監聽器,有沒有辦法做到這一點? –

0
Animator animation = AnimatorInflater.loadAnimator(getApplicationContext(), 
         R.animator.selectzoom);//selectzoom is a xml file of your animation 

要動畫添加到一個圖像,基於在imageview的陣列的圖像值的索引

animation.setTarget(imageView[animaterimg]);//imageView is a array of your images views 
animation.start(); 

要停止動畫一個圖像,基於在imageview的陣列的圖像值的索引

imageView[animaterimg].clearAnimation(); 
imageView[animaterimg].animate().cancel(); 

selectzoom必須在動畫文件夾

<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <objectAnimator 
     android:duration="1000" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:repeatCount="infinite" 
     android:repeatMode="reverse"/> 

    <objectAnimator 
     android:duration="1000" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:propertyName="scaleX" 
     android:repeatCount="infinite" 
     android:repeatMode="reverse" /> 

</set>