我可以在 1 秒內使用 textview 為分數變數的增加設定影片嗎?
uj5u.com熱心網友回復:
我強烈建議使用檢查這個問題,有各種方法對不同的情況有不同的作用。
你可以試試:
//You can animate from a specified starting point till the final score
val valueAnimator = ValueAnimator.ofInt(initialScore, finalScore)
//Here you set the duration of the animation in milliseconds
valueAnimator.duration = 1000
valueAnimator.addUpdateListener { valueAnimator ->
//The textview gets updates as the value animator's value updates
textView.text = valueAnimator.animatedValue.toString()
}
//Here you just start the animation
valueAnimator.start()
這也可以重新用于它自己的方法;)
uj5u.com熱心網友回復:
另一種有效的方法是使用 new Handler(Looper.getMainLooper()).postDelayed(new Runnable() ... 例如:
private void wonBlockIncreaseScore() {
int oldScore = score;
score = score 50;
int timeOverWhichAnimationShouldRun = 1000; //ms
int equalGap = (timeOverWhichAnimationShouldRun / (score-oldScore));
//equal gap...
for (int i = oldScore; i < score; i ) {
int finalI = i;
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
scoreTextView.setText(String.valueOf(finalI 1));
}
}, (equalGap * i));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/396844.html
上一篇:Kotlin接收器名稱沖突
