如何在TextView中制作计数动画

Ric*_*cci 2 java android textview sharedpreferences

因此,在我的游戏中,有一个计分选项卡将在游戏结束时显示

这是我的标签得分示例

这是代码:

    highscoretext = (TextView)findViewById(R.id.bt);
    highscoretext.setText("0");

    currentscore = (TextView)findViewById(R.id.ct);
    currentscore.setText(String.valueOf(gamescore));
Run Code Online (Sandbox Code Playgroud)

这就是我保存将在最佳成绩中显示的分数的方式

           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();    
Run Code Online (Sandbox Code Playgroud)

我不知道做一个动画来我TextView喜欢这个

因此,当显示标签分数时,分数将从0计入游戏中获得的当前分数,例如:10

并且当分数停止计数时,如果分数>最佳分数,则最佳分数的值会更改

谁能帮我?

Ram*_*ami 5

对于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();
Run Code Online (Sandbox Code Playgroud)