所以在我的游戏中有一个分数标签会在游戏结束时显示
这是我的标签得分的例子
这是代码:
highscoretext = (TextView)findViewById(R.id.bt);
highscoretext.setText("0");
currentscore = (TextView)findViewById(R.id.ct);
currentscore.setText(String.valueOf(gamescore));
这就是我如何保存将在 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
制作动画
所以当tab得分显示时,得分会从0开始计算到游戏中的当前得分,例如:10
当score停止计数时,如果score > best score,则best score中的值发生变化
谁能帮帮我?
最佳答案
对于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();
关于java - 如何在TextView中制作计数动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33839865/