2016-10-11 170 views
-2
<?xml version="1.0" encoding="utf-8"?> 
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" 
    android:propertyName="rotationX" 
    android:valueFrom="0" 
    android:valueTo="-360" 
    android:repeatCount="infinite"> 
</objectAnimator> 

這是我的目標動畫XMLObjectAnimator重複循環延遲

//Animating the NormalLayout 
    final ObjectAnimator anim4 = (ObjectAnimator) //Object animator 
    AnimatorInflater.loadAnimator(this, R.animator.rotate_four); 
//And this is my java code 

我想它的循環之間添加延遲,如再次循環之間3秒。我曾嘗試動畫聽衆onRepeat,onEnd有點東西,但它沒有奏效。我想循環之間有一些延遲。

任何幫助將被讚賞的最大限度。

+0

在提出問題之前,請參閱[如何提問](http://stackoverflow.com/help/asking)。只要問你想要什麼,不要閒聊! –

回答

0

請嘗試 1.delete xml屬性android:repeatCount="infinite" 2.加java代碼

anim4.addListener(new AnimatorListenerAdapter(){ 
    @Override 
    public void onAnimationEnd(Animator animation) { 
     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       anim4.start(); 
      } 
     }, 3000); 
    } 
}); 
0

Helper類

public class DelayedAnimationRepeater implements Animator.AnimatorListener { 
    private long delayMillis; 

    public DelayedAnimationRepeater(long delayMillis) { 
     this.delayMillis = delayMillis; 
    } 

    @Override 
    public void onAnimationStart(Animator animator) { 

    } 

    @Override 
    public void onAnimationEnd(final Animator animator) { 
     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       // Start delay should only affect initial start, not repeats 
       animator.setStartDelay(0); 
       animator.start(); 
      } 
     }, delayMillis); 
    } 

    @Override 
    public void onAnimationCancel(Animator animator) { 

    } 

    @Override 
    public void onAnimationRepeat(Animator animator) { 

    } 
} 

使用

anim4.addListener(new DelayedAnimationRepeater(3000));