When it comes to dynamic increment setting TextView value, very many people should immediately think of a thread, let the after-thread sleep for a specified time, use handler send message update TextView value!
This is the realization of the dynamic increment setting TextView value but the efficiency is not good drop bar, need to be able to try their own, such as 1 to 100,10s within the display, will feel a bit of card.
Here's a better way to set it up with Valueanimator, without having to calculate the time required for each overlay, here's the code:
public static void AutoIncrement (final TextView target, final float start,final float end, long duration) {Valueanimator A Nimator = Valueanimator.offloat (start, end); Animator.addupdatelistener (new Animatorupdatelistener () {Private Floatevaluator evalutor = new Floatevaluator ();p rivate decimalformat format = new DecimalFormat ("# # # #0.0#"); overridepublic void Onanimationupdate (Valueanimator animation) {Float fraction = animation.getanimatedfraction (); float CurrentValue = evalutor.evaluate (fraction, start, end); Target.settext (Format.format (CurrentValue));}); Animator.setduration (duration); Animator.start ();}
A value of 1-1000 is displayed within 2s. The display is smooth. Don't believe you can try it yourself!
Android Dynamic set TextView value, example: Amount added