2014-12-02 93 views
2

我在Android中實現了一臺老虎機。卷軸是帶有LinearLayouts作爲子項的ScrollViews,以及在LinearLayout內部垂直定向的作爲ImageViews的各個tile。我使用ObjectAnimator滾動到ScrollView的末尾,使用ValueAnimator.RESTART和ValueAnimator.INFINITE。卷軸的滾動很好而且很流暢,但是當它重複時,它會暫停一秒,這會破壞效果。以下是我正在使用的代碼:Android中的循環動畫ScrollView在重複之間暫停

public void spinReel(SlotReel reel) { 
     final int reelSize = this.context.getPixelsInDPs(64); 
     final SlotMachineView me = this; 
     final SlotReel myReel = reel; 
     ImageView[] tiles = reel.getTiles(); 
     int delta = tiles.length - reel.currentTileNumber(); 
     ObjectAnimator animator = ObjectAnimator.ofInt(reel, "scrollY", tiles.length * reelSize); 
     animator.setInterpolator(new LinearInterpolator()); 
     animator.setDuration(delta * 75); 
     animator.setStartDelay(0); 
     animator.setRepeatMode(ValueAnimator.RESTART); 
     animator.setRepeatCount(ValueAnimator.INFINITE); 
     animator.addListener(new Animator.AnimatorListener() { 
      @Override 
      public void onAnimationStart(Animator animator) { 

      } 

      @Override 
      public void onAnimationEnd(Animator animator) { 
      } 

      @Override 
      public void onAnimationCancel(Animator animator) { 

      } 

      @Override 
      public void onAnimationRepeat(Animator animator) { 
       myReel.scrollTo(0, reelSize * 3); 

      } 
     }); 
     animator.start(); 

    } 

請注意,無論是否將scrollTo放入Repeat回調中,都會出現急動度。

實例視頻here

回答