Note that there are some explanatory texts on larger screens.

plurals
  1. POValueAnimator only repeats once
    text
    copied!<p>I am trying to get a <code>ValueAnimator</code> to repeat once it has ended. I am using it with a <code>SeekBar</code> in a <code>ListView</code>. For some reason, the <code>ValueAnimator</code> will finish, trigger the <code>onAnimationEnd()</code> go again, but then when it reaches the end the <code>onAnimationEnd()</code> is never called a second time.</p> <pre><code> @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)); } </code></pre> <hr> <p>The <code>seekBar</code> object is actually an custom object which contains a <code>SeekBar</code> and a <code>ValueAnimator</code>, here are the relevant bits:</p> <pre><code> //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 &gt; 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); } </code></pre> <hr> <p>I can't figure out why it isn't repeating more than twice.</p> <p>I've tried using the <code>Repeat</code> attribute and setting that to <code>INIFINITI</code> but that didn't help either.</p> <hr> <p>Edit: To be clear, what I am trying to get is an animation that repeats itself indefinitely, each time with a different duration.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload