我试图在ValueAnimator
它结束后重复一遍.我使用它与一个SeekBar
在ListView
.由于某种原因,ValueAnimator
将完成,onAnimationEnd()
再次触发,但是当它到达结束时,onAnimationEnd()
从未被称为第二次.
@Override public View getContentView(int position, View convertView, ViewGroup parent) { ... setupTimerBar(t); ... } private AnimatorListenerAdapter generateNewAnimatorListenerAdapter(final TylersContainer t) { return new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setupTimerBar(t); } }; } private void setupTimerBar(TylersContainer t) { View view = t.getView(); BusTime arrivalTime = t.getBusTime(); int minutes = BusTime.differenceInMiuntes(arrivalTime, BusTime.now()); long milliseconds = minutes * 60 * 1000; final TimerBar seekBar = (TimerBar) view.findViewById(R.id.SeekBar); int progress = Utility.setProgress(arrivalTime, seekBar.getMax()); long duration = Utility.setAnimationDuration(progress); seekBar.setProgress(progress); seekBar.setAnimationDuration(duration); seekBar.setAnimationStartDelay(milliseconds); seekBar.setAnimatorListenerAdapter(generateNewAnimatorListenerAdapter(t)); }
该seekBar
对象实际上是一个自定义对象,其中包含a SeekBar
和a ValueAnimator
,以下是相关位:
//Constructor public TimerBar(Context context) { super(context); startTime = Calendar.getInstance(); valueAnimator = ValueAnimator.ofInt(0, getMax()); //Override the update to set this object progress to the animation's value valueAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int animProgress = (Integer) animation.getAnimatedValue(); setProgress(animProgress); } }); } //Specify the start time by passing a long, representing the delay in milliseconds public void setAnimationStartDelay(long milliseconds){ //Set the delay (if need be) and start the counter if(milliseconds > 0) valueAnimator.setStartDelay(milliseconds); valueAnimator.setIntValues(this.getProgress(), this.getMax()); valueAnimator.start(); } //Set the duration of the animation public void setAnimationDuration(long duration){ valueAnimator.setDuration(duration); } public void setAnimatorListenerAdapter(AnimatorListenerAdapter ala){ valueAnimator.addListener(ala); }
我无法弄清楚为什么它不会重复两次以上.
我已经尝试使用该Repeat
属性并将其设置为INIFINITI
但是这也没有帮助.
编辑:要清楚,我想要得到的是一个无限期重复的动画,每次都有不同的持续时间.
我已经将设置RepeatMode
为无限的错误设置为无效,这必须设置为RepeatCount
:
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);