When it comes to the dynamic increment setting TextView value, many people should immediately think of a thread, let the post-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, if necessary, you can try it yourself, 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 ();}
In the 2s display 1-1000 of the value, the display is very smooth, do not believe you can try it yourself!
Android Dynamic set TextView value, example: increase in amount