Android 實現滾動數字的TextView
阿新 • • 發佈:2019-02-14
在很多時候,我們都希望Android介面中的TextView數字滾動顯示以增加檢視的趣味性,
1.在此,實現Android的滾動數字TextView:
2.之後,呼叫runWithAnimation()方法即可實現期望的效果。public class RunTextView extends TextView { private int duration = 1500; private float number; public float getNumber() { return number; } public void setNumber(float number) { this.number = number; setText(String.format("%,.2f",number)); } public RunTextView(Context context, AttributeSet attrs) { super(context, attrs); } /** * 顯示 * @param number */ public void runWithAnimation(float number){ ObjectAnimator objectAnimator = ObjectAnimator.ofFloat( this, "number", 0, number); objectAnimator.setDuration(duration); objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); objectAnimator.start(); } }