Android Dynamic set TextView value, example: increase in amount

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.