我是新来的android开发,我想知道是否有可能在Android中添加一个“秒针”到默认的模拟时钟?Android时钟秒针
我已经有一个拨号,时针和分针的工作时钟。我搜索了一遍,我偶然发现了一些帖子,指出你需要一个在后台运行的服务来每秒钟更新时钟。这是一个时钟小部件,而矿井是一个应用程序。
请问有什么办法可以做到?
我是新来的android开发,我想知道是否有可能在Android中添加一个“秒针”到默认的模拟时钟?Android时钟秒针
我已经有一个拨号,时针和分针的工作时钟。我搜索了一遍,我偶然发现了一些帖子,指出你需要一个在后台运行的服务来每秒钟更新时钟。这是一个时钟小部件,而矿井是一个应用程序。
请问有什么办法可以做到?
这里是如何做到这一点:http://developer.android.com/resources/articles/timed-ui-updates.html
警告:这样做会非常快耗尽电池!
如果您已经使用时针和分针自己绘制时钟,那么秒针的问题到底是什么?更新它只是更新其他手,只需将更新线程的频率增加到一秒。
是的,这是可能把二手机器人模拟时钟我已经在我的应用程序做过,请看到它可以帮助你,如果你发现任何错误而不是评论这里。 这里的链接是you can find it here in link
private ImageView img;
Handler mHandler;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread myThread = null;
Runnable runnable = new CountDownRunner();
myThread = new Thread(runnable);
myThread.start();
}
public void doRotate() {
runOnUiThread(new Runnable() {
public void run() {
try {
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = hours + ":" + minutes + "::" + seconds;
Log.v("log_tag", "Log is here Time is now" + curTime);
img = (ImageView) findViewById(R.id.imgsecond);
RotateAnimation rotateAnimation = new RotateAnimation(
(seconds - 1) * 6, seconds * 6,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
img.startAnimation(rotateAnimation);
} catch (Exception e) {
}
}
});
}
class CountDownRunner implements Runnable {
// @Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
doRotate();
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
Log.e("log_tag", "Error is " + e.toString());
}
}
}
}
非常感谢,这样我就可以应用此默认模拟时钟?这里的例子是数字计时器。是的,如果我能得到它的工作,肯定会需要充电,而时钟显示哈哈。再次感谢 – user581949 2011-01-20 15:43:08