implementation 'wellijohn.org.tvanim:animtv:1.0.0'android
<wellijohn.org.animtv.AnimTextView android:id="@+id/atv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" app:textColor="@color/colorAccent" app:textSize="20sp" app:duration="5000"/>
使用的時候,直接在animTv.setText(222.09);就能夠了,在這裏須要注意的是,這裏的數值只支持整型和小數顯示,小數只支持到小數點後兩個位,若是有小數點後有3位以上,自動四捨五入git
ValueAnimator va; if (mIsInteger) { va = ValueAnimator.ofInt(0, (Integer) mEndText); } else { va = ValueAnimator.ofFloat(0, Float.parseFloat(String.valueOf(mEndText))); } va.setDuration(mDuration); va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mDrawText = mIsInteger ? (T) animation.getAnimatedValue() : (T) df.format(animation.getAnimatedValue()); ViewCompat.postInvalidateOnAnimation(AnimTextView.this); } }); va.start();
另外須要注意的是重寫onMeasure方法,支持padding,width爲wrap_content屬性的大小設置。這裏是一個很是簡單的,拿來練練手,等有時間作點上下滾動的特效。
github地址github