2015-11-21 36 views
1

所以在我的比賽有得分選項卡,將在GAMEOVER顯示如何使計數動畫的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

和比分時停止計數,如果分數>最好成績,以最好成績的值改爲

誰能幫助我?

回答

2

對於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(); 
+1

哦好,這就是工作謝謝 – Ricci

+0

@Archanister歡迎您! – Rami