最近做了个小实验--一个小的计数秒表,实现开始计时,暂停计时,重置的功能。界面如下
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAS4AAAHgCAIAAACUwBfQAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAACX8SURBVHhe7Z2Jd01X/8bvH/J769Q8j6Xt2yreVktLa4pZzaI1VJRWSk01hIipNRNCTDXUnBCCEDLPIQkJIYSYIiGI4f095+7trOtGBnFz9/au57OeZe393fucm67e536/e59z77G1aPFBixYt2nQ9SFGUQtk+gBWb04oUpVi2Fs1hxQ+cohRFuVmwYgtmRYpSLlqRorSQaUUsF52iFEW5WbYPmn8AOUUpinKzaEWK0kK0IkVpIbFtQytSlGLZt23caMWOfYO/GxjiFNRfPn8mhpzMGTTmhFOcolylN8iKx09f+e9///v06fNug1/x0oQZkYiDiTMjHeNOWrEh9emzF2Im2LzrQttuZvyr3kETp5/p90Oo4+SKKzLuJs7WY+hR0d36Tya6S1YniO6ilUnoHgq5LLol1a77Ibw61M7+x5SmvcHZOM/4qWec4hTlKr3BWlFYEWzake4Yj4y5LuJlWHHmgugXL17k3nwYuDMjYHvalZxCzF+z6RyGBo49jnbgzguO8ysuHIjD/1qbKLpJqbfRDY+6Ibp/78tC1/uPs6JbUsjSmAC+7BXsNOQoWpGqaiErVvTGN2HF4qfPL1+5bwV7jTj24sV/i4qeYQhW7Nj3MOrPLzyCxOjX/cwuMk98sumQ6fOjRPzLXkFFj55ezLoHJ4z+LRxDO/Zndf7+iBj9qnfwmN/CFyyL9xh+7D89DokgTvXtwBAMjZtyZvbC2G/6HxbxKXPNnHz89HW023Y9eL/gCf6em7eK2nUzD0xKvYUXEjO/8DjU74fjfsvjf5kZgddF5HOPQ71HhuJwgNdq39P8s3GSTgOOzFoYM3lOJF5UHCusOHH62f6jTuAP6zMytOwsSlFvKtOKb5QVk8/devb8hccwWaMuWZOCt/7W3WZqghUXr0lBY+8hmeIuXrr36PE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LFBthBCF2Gz/D5zKyd87wdf7AAAAAElFTkSuQmCC" alt="" />
界面过于简单,这里就飘过。
制作这个秒表主要用到Chronometer类的start()函数,stop()函数,setBase()函数。
查了下源码,这个Chronometer的原理就是先设置一个mBase变量,在类被创建时调用init函数将系统启动后所用掉的时间赋给mBase。源码如下
而Chronometer控件显示的时间就是 : 系统启动后所用掉的时间 - mBase
当你想让秒表开始计时就调用start函数,这是Chronometer就会自己刷新时间。
而想暂停就调用stop函数,问题就是一个stop函数,这个stop函数只是停止Chronometer刷新时间,而系统的时间还是在继续计时的。
当你再次调用start函数时,刷新的时间就不是你调用stop函数那一刻的时间,而是从你创建类开始所经过的时间。
而如果想要实现继续功能就需要费电功夫了。
我的实现方法就是,在按下stop时就把当前系统的时间保存起来,当按下开始时重新设置mBase变量,从而使当前显示时间不变并继续计时。
具体代码如下:
switch (v.getId()){
case R.id.btn_start:
if(!flag){
flag = !flag;
if(mRecordTime != 0){
Chron.setBase(Chron.getBase() + (SystemClock.elapsedRealtime() - mRecordTime));
}else{
Chron.setBase(SystemClock.elapsedRealtime());
}
Chron.start();
}
break;
case R.id.btn_stop:
if(flag){
flag = !flag;
Chron.stop();
mRecordTime = SystemClock.elapsedRealtime();
}
break;
case R.id.btn_reset:
Chron.stop();
Chron.setBase(SystemClock.elapsedRealtime());
mRecordTime = 0;
flag = false;
break;
default: break;
}
同时还定义了一个boolean的变量,防止因为乱按而使得时间出现错乱。
这次的代码过于简单就不贴源码了。-_-#