动画的TextView增加的整数,并停止在某些时候? [英] Animate TextView to increase integer and stop at some point?
本文介绍了动画的TextView增加的整数,并停止在某些时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个TextView显示整数值。整数值是由previous活动转移,我想添加漂亮的动画。我想如果例如int值是73,我想的TextView增加1所示的数量,直到73,所以这将是1-2-3-4-5 ...等等等等。 我怎样才能做到这一点?
I have a TextView showing integer value. Integer value is transferred from previous activity, and I want to add nice animation. I want to if for example int value is 73, I want textView to increase shown number by 1 until 73, so it would be 1-2-3-4-5...etc etc. How can I do this?
推荐答案
下面是一个简单的功能,根据最初和最终值动画一个TextView的文本
Here is a simple function to animate the text of a textView according to an initial and final value
public void animateTextView(int initialValue, int finalValue, final TextView textview) {
DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(0.8f);
int start = Math.min(initialValue, finalValue);
int end = Math.max(initialValue, finalValue);
int difference = Math.abs(finalValue - initialValue);
Handler handler = new Handler();
for (int count = start; count <= end; count++) {
int time = Math.round(decelerateInterpolator.getInterpolation((((float) count) / difference)) * 100) * count;
final int finalCount = ((initialValue > finalValue) ? initialValue - count : count);
handler.postDelayed(new Runnable() {
@Override
public void run() {
textview.setText(finalCount + "");
}
}, time);
}
}
这篇关于动画的TextView增加的整数,并停止在某些时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文