[英]How to make count animation in TextView
因此,在我的游戏中,有一个得分选项卡将在游戏结束时显示
这是我的标签得分示例
这是代码:
highscoretext = (TextView)findViewById(R.id.bt);
highscoretext.setText("0");
currentscore = (TextView)findViewById(R.id.ct);
currentscore.setText(String.valueOf(gamescore));
这就是我保存将在最佳成绩中显示的分数的方式
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
并且当分数停止计数时,如果分数>最佳分数,则最佳分数的值会更改
谁能帮我?
对于API> 11 ,我建议您使用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();
使用某种计时器来实现应该相当简单。 每次击中计时器时,您便会增加分数并更新显示,除非达到最终分数。
可以使用Handlers( http://developer.android.com/reference/android/os/Handler.html )或java.util.Timer( http://docs.oracle.com/javase/7/docs/ api / java / util / Timer.html ),尽管后一种方法可能不适用于Android开发。
(来源: 如何在android中设置计时器 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.