刚开始有大概2秒延时,怎么回事
 final TextView timeout = (TextView)grid.findViewById(R.id.timeout);
 final ImageButton tock_on = (ImageButton) grid.findViewById(R.id.tock_on);
  tock_on.setOnClickListener(new View.OnClickListener() {
                public void onClick(View arg0) {
 timeout.setText("00:00:00");
                            stepTimeHandler = new Handler();
                            startTime = System.currentTimeMillis();
                            mTicker = new Runnable() {
                            public void run() {
                                String content = showTimeCount(System.currentTimeMillis() - startTime);
                                timeout.setText(content);
                                long now = SystemClock.uptimeMillis();
                                long next = now + (1000 - now % 1000);
                                stepTimeHandler.postAtTime(mTicker, next);
                            }
                    };
                    //启动计时线程,定时更新
                    mTicker.run();
                                         }
            });版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
第一次执行时间也就是new runnalbe和执行showtimecount的时间,应该不至于这么慢。不过如果是text偶尔跳动2秒是有可能的。先不说系统延时之类的。就从逻辑分析是有可能的
 stepTimeHandler = new Handler();
                            startTime = System.currentTimeMillis();
                            mTicker = new Runnable() {
                            public void run() {
                                String content = showTimeCount(System.currentTimeMillis() - startTime);System.currentTimeMillis() 是999毫秒,相差不到1秒,显示应该还是00:00:00
                                timeout.setText(content);
                                long now = SystemClock.uptimeMillis();//这里比如SystemClock.uptimeMillis() 刚好过了当前秒了,是1秒001毫秒
                                long next = now + (1000 - now % 1000);//到这里下次执行时间就是2秒的时候执行
                                stepTimeHandler.postAtTime(mTicker, next);//再加上post延时,下次显示就是00:00:02了
                            }