在很多时候,我们都希望Android界面中的TextView数字滚动显示以增加视图的趣味性,
1.在此,实现Android的滚动数字TextView:
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();
}
}