The effect of a simple rolling number

Posted by r3drain on Thu, 30 Apr 2020 15:14:46 +0200

1. Renderings

2. Custom attributes

  • textColor font color
  • textSize font size
  • Time displayed in duration text

3. Instructions

Step 1. Add it in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            maven { url '' }
Step 2. Add the dependency

    dependencies {
            compile 'com.github.WelliJohn:AnimTextView:1.0.0'

When using, you can use it directly in animTv.setText(222.09); it is OK. Here, you need to note that the value only supports integer and decimal display, and the decimal only supports two decimal places. If there are more than three decimal places after the decimal point, it will be automatically rounded

4. The idea of implementation is very simple. An animation is solved. The number displayed is traversed from 0 to once, and then the ui is refreshed.

 ValueAnimator va;
        if (mIsInteger) {
            va = ValueAnimator.ofInt(0, (Integer) mEndText);
        } else {
            va = ValueAnimator.ofFloat(0, Float.parseFloat(String.valueOf(mEndText)));

        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                mDrawText = mIsInteger ? (T) animation.getAnimatedValue() : (T) df.format(animation.getAnimatedValue());

In addition, it should be noted that the onMeasure method is overridden to support padding, and the width is set to the size of the wrap content property. Here is a very simple, to practice hands, waiting for time to do point up and down rolling effect.
github address , your praise and star are the biggest driving force for me to continue to open source.

Topics: Android github Gradle Maven