如何在TextView的计数动画 [英] How to make count animation in TextView
本文介绍了如何在TextView的计数动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,在我的比赛有得分选项卡,将在GAMEOVER显示
So in my game there is score tab that will show in gameover
这是我的标签成绩例如
这是code:
highscoretext = (TextView)findViewById(R.id.bt);
highscoretext.setText("0");
currentscore = (TextView)findViewById(R.id.ct);
currentscore.setText(String.valueOf(gamescore));
这就是我如何保存将bestscore
And this is how i save the score that will display in bestscore
SharedPreferences pref = getSharedPreferences("SavedGame", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putInt("totalScore", gamescore);
if (gamescore > highscore){
highscoretext.setText(String.valueOf(gamescore));
editor.putInt("highscore", gamescore);
editor.commit();
我不知道做一个动画来我的TextView
像这样
所以,当标签显示得分,将比分从0数到当前比分的比赛中,例子,得到:10
So when the tab score display, the score will count from 0 to Current score that get in the game, example : 10
和比分时停止计数,如果分数>最好成绩,以最好成绩的值不同。
and when score stop count, if the score > best score, the value in best score changed
谁能帮我?
推荐答案
对于 API> 11 ,我建议你使用的 ValueAnimator :
For API >11, i suggest you to use ValueAnimator:
ValueAnimator animator = new ValueAnimator();
animator.setObjectValues(0, count);// here you set the range, from 0 to "count" value
animator.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
highscoretext.setText(String.valueOf(animation.getAnimatedValue()));
}
});
animator.setDuration(1000); // here you set the duration of the anim
animator.start();
这篇关于如何在TextView的计数动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文