Android Imitation Alipay balance treasure in the digital animation effect _android

Source: Internet
Author: User
Tags float number

To implement the effect diagram:

Here is the specific code that can be copied directly:

Package com.lcw.rabbit.widget;
Import Android.animation.ObjectAnimator;
Import Android.content.Context;
Import Android.text.TextUtils;
Import Android.util.AttributeSet;
Import Android.view.animation.AccelerateDecelerateInterpolator;

Import Android.widget.TextView;  /** * High imitation balance treasure Digital Animation * Create By:chenwei.li * date:2016-07-20 * time:11:52 * email:lichenwei.me@foxmail.com/Public
 Class Countnumberview extends TextView {//animation time long private int duration = 1500;
 Display digital private float number;

 Displays an expression private String regex; Displays the expression public static final string Intregex = "%1$01.0f";//No decimal, Integer public static final String Floatregex = "%1$01.2f";
 /Keep 2 decimal countnumberview (context, AttributeSet attrs) {Super (context, attrs); /** * Displays the animated number * @param numbers * @param regex */public void shownumberwithanimation (float, String rege
 x) {if (Textutils.isempty (regex)) {//default is integer This.regex = Intregex;
 else {This.regex = regex; }//Modify the Number property to call theSetnumber method Objectanimator Objectanimator = Objectanimator.offloat (This, "number", 0, number);
 Objectanimator.setduration (duration);
 Accelerator, from slow to fast to slow objectanimator.setinterpolator (new Acceleratedecelerateinterpolator ());
 Objectanimator.start ();
 /** * Get current digit * @return/public float GetNumber () {return number;
 /** * According to regular expression, display corresponding digital style * @param number/public void Setnumber (float number) {this.number = #;
 SetText (String.Format (regex, number)); }
}

Using the method, which is declared in XML (which can be used entirely as TextView), is invoked directly in the Java file:

 Mtvcountnum1.shownumberwithanimation (3201.23f, Countnumberview.floatregex);
 Mtvcountnum2.shownumberwithanimation (65535f, Countnumberview.intregex);

Here for flexible use, set aside the digital display format (the default to provide a full model and floating-point type), you can change according to their own needs Regex .

The first format parameter for String.Format, which references the description of the following API:

The syntax for format specifiers for general types, character types, and numeric types is as follows:

%[argument_index$][flags][width][.precision]conversion

Optionally argument_index , a decimal integer indicating the position of the parameter in the parameter list. The first parameter is referenced by "1$", the second parameter is referenced by "2$", and so on.

Optional flags is the character set that modifies the output format. The set of valid flags depends on the type of conversion.

Optionally width , a nonnegative decimal integer indicating the minimum number of characters to write to the output.

Optional precision is a nonnegative decimal integer that is typically used to limit the number of characters. Specific behavior depends on the type of conversion.

Summarize

Android fake Alipay digital animation effect to this end, I hope this article for everyone in the development of Android can help, if you have questions can message exchange.

Related Article

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.