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