Android : Count-up textview android

on Monday, March 23, 2015


I want to create a count-up/count-down effect on a textview and i found this code here:


How to create a count-up effect for a textView in Android


Code:



ValueAnimator animator = new ValueAnimator();
animator.setObjectValues(valueA, valueB);
animator.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
view.setText(String.valueOf(animation.getAnimatedValue()));
}
});
animator.setEvaluator(new TypeEvaluator<Integer>() {
public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
return Math.round((endValue - startValue) * fraction);
}
});
animator.setDuration(1000);
animator.start();


Problem is that this code will always count from 0 to valueA - valueB, and i need this counting between 2 specific values (not from 0 to specific value).


Any sugestions?


Thank you!


0 comments:

Post a Comment