机器人计时器?怎么.?有人能给出一个简单的例子,每隔一秒更新一个文本字段吗?我想做一个飞行的球,每秒钟都需要计算/更新球坐标,这就是为什么我需要一个定时器。我什么也得不到这里.
3 回答
![?](http://img1.sycdn.imooc.com/54585094000184e602200220-100-100.jpg)
墨色风雨
TA贡献1853条经验 获得超6个赞
Timer timer = new Timer();
class UpdateBallTask extends TimerTask { Ball myBall; public void run() { //calculate the new position of myBall }}
final int FPS = 40;TimerTask updateBall = new UpdateBallTask();timer.scheduleAtFixedRate(updateBall, 0, 1000/FPS);
免责声明:这不是理想的解决方案。这是使用Timer类的解决方案(正如OP所要求的)。在AndroidSDK中,建议使用Handler类(在接受的答案中有示例)。
- 3 回答
- 0 关注
- 599 浏览
添加回答
举报
0/150
提交
取消