安卓倒计时 [英] Android countdown

查看:122
本文介绍了安卓倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写在Android的倒计时它开始在出现,然后消失,2出现等等计数从3到0喜欢在第一次3。我搜索了很多,但我找不到任何好的样本。你能帮助我,我该怎么办?

I want to write a countdown in android which starts counting from 3 to 0. Like at first 3 in appearing and then disappearing and 2 is appearing and so on. I searched a lot but I couldn't find any good sample. Can you help me that what should I do?

推荐答案

使用CountDownTimer

use CountDownTimer

例如:

import android.os.CountDownTimer;   

MyCount timerCount;
public class TestCountdown extends Activity {

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    timerCount = new MyCount(3 * 1000, 1000);
    timerCount.start();
  }

  public class MyCount extends CountDownTimer {
      public MyCount(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
      }

      @Override
      public void onFinish() {
        //some script here
      }

      @Override
      public void onTick(long millisUntilFinished) {
        //some script here 
      }   
    } 
}

这篇关于安卓倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆