本文实例为大家分享了Android实现定时器和倒计时的具体代码,供大家参考,具体内容如下
直接上代码,相信都看得懂。
Android已经帮封装好了一个类,只不过很多人不知道而已。
代码:
公开课SplashActivity延伸BaseAppCompatActivity { @InjectView (R.id.ivBg) ImageView ivBg; @InjectView (R.id.tvSkip) TextView tvSkip; int[]一个=new int [] { R.mipmap.irving, R.mipmap.bryant, R.mipmap.james, R.mipmap.harden, R.mipmap.curry}; 私人CountDownTimer定时器; @Override 保护int getContentViewLayoutID () { 返回R.layout.activity_splash; } @Override 保护无效initViewsAndEvents () { int指数=(int) (math . random () * imgs.length); ivBg.setImageResource(一个(指数)); 计时器=new CountDownTimer (3500、1000) { @Override 公共空间> & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " android: layout_width=" match_parent " android: layout_height=癿atch_parent”比; & lt; ImageView android: id=癅 + id/ivBg” android: layout_width=" match_parent " android: layout_height=" match_parent " android: scaleType=" fitXY "/比; & lt; TextView android: id=癅 + id/tvSkip” android: layout_width=" wrap_content " android: layout_height=" wrap_content " android: layout_alignParentRight=" true " android: layout_alignParentTop=" true " android: layout_margin=" 10 dp” android:背景=" @drawable/common_button_selector” android:填充=" 5 dp " android:文本=癅string/跳过”/比; & lt;/RelativeLayout> >之前以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
Android CountDownTimer实现定时器和倒计时效果