【发布时间】:2014-07-06 06:25:27
【问题描述】:
应用中有一个定时器,编码如下:
private Runnable updateTimerThread = new Runnable()
{
public void run()
{
if (game_pause ==false)
{
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
text_time.setText("" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));
customHandler.postDelayed(this, 0);
if (milliseconds % 10 == 0)
{
update_score_level(1);
}
}
else
{
text_time.setText("Paused!");
}
}
};
问题:
每个if (milliseconds % 10 == 0) 都会更新分数。但是,这样编码虽然时间流畅,但是分数的更新显得极其不流畅(不是线性速度,时快时慢)。
想以这种方式展示: 0:00:100 ---> 得分+1; 0:00:200 ---> 得分+1; 0:00:300 ---> 得分+1; 上面的怎么修改?
谢谢!
【问题讨论】:
标签: android performance time timer