Android仿活動(dòng)時(shí)分秒倒計(jì)時(shí)效果
本文實(shí)例為大家分享了Android時(shí)分秒倒計(jì)時(shí)效果的具體代碼,供大家參考,具體內(nèi)容如下
從mian.xml下手:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="離結(jié)束時(shí)間為:"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="10dp" android:orientation="horizontal"> <TextView android:id="@+id/tvtime1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:gravity="center" android:background="#3B3B3B" android:text="12" android:textColor="#FFFFFF" android:textSize="30sp" /> <TextView android:id="@+id/tvtime2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:gravity="center" android:text="12" android:textColor="#FFFFFF" android:background="#3B3B3B" android:textSize="30sp" /> <TextView android:id="@+id/tvtime3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:gravity="center" android:background="#3B3B3B" android:textColor="#FFFFFF" android:text="13" android:textSize="30sp" /> </LinearLayout> </LinearLayout>
MainActivity
public class MainActivity extends Activity { private TextView tvtime1,tvtime2,tvtime3; private long time=400; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvtime1=(TextView)findViewById(R.id.tvtime1); tvtime2=(TextView) findViewById(R.id.tvtime2); tvtime3=(TextView) findViewById(R.id.tvtime3); handler.postDelayed(runnable, 1000); } Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { time--; String formatLongToTimeStr = formatLongToTimeStr(time); String[] split = formatLongToTimeStr.split(":"); for (int i = 0; i < split.length; i++) { if(i==0){ tvtime1.setText(split[0]+"小時(shí)"); } if(i==1){ tvtime2.setText(split[1]+"分鐘"); } if(i==2){ tvtime3.setText(split[2]+"秒"); } } if(time>0){ handler.postDelayed(this, 1000); } } }; public String formatLongToTimeStr(Long l) { int hour = 0; int minute = 0; int second = 0; second = l.intValue() ; if (second > 60) { minute = second / 60; //取整 second = second % 60; //取余 } if (minute > 60) { hour = minute / 60; minute = minute % 60; } String strtime = hour+":"+minute+":"+second; return strtime; } }
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android自定義DigitalClock控件實(shí)現(xiàn)商品倒計(jì)時(shí)
- Android計(jì)時(shí)與倒計(jì)時(shí)實(shí)現(xiàn)限時(shí)搶購(gòu)的5種方法
- Android定時(shí)器和倒計(jì)時(shí)實(shí)現(xiàn)淘寶秒殺功能
- Android CountDownTimer實(shí)現(xiàn)定時(shí)器和倒計(jì)時(shí)效果
- android自定義倒計(jì)時(shí)控件示例
- android實(shí)現(xiàn)倒計(jì)時(shí)功能代碼
- Android實(shí)現(xiàn)計(jì)時(shí)與倒計(jì)時(shí)的常用方法小結(jié)
- Android實(shí)現(xiàn)加載廣告圖片和倒計(jì)時(shí)的開(kāi)屏布局
- Android 實(shí)現(xiàn)閃屏頁(yè)和右上角的倒計(jì)時(shí)跳轉(zhuǎn)實(shí)例代碼
- Android實(shí)現(xiàn)精確到天時(shí)分秒的搶購(gòu)倒計(jì)時(shí)
相關(guān)文章
Android 中HttpURLConnection與HttpClient使用的簡(jiǎn)單實(shí)例
這篇文章介紹了Android 中HttpURLConnection與HttpClient使用的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-10-10Android自定義Drawable實(shí)現(xiàn)圓角效果
這篇文章主要為大家詳細(xì)介紹了Android自定義Drawable實(shí)現(xiàn)圓角效果,實(shí)現(xiàn)一個(gè)圓形和圓角的背景圖片效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08Android開(kāi)發(fā)微信小程序路由跳轉(zhuǎn)方式
這篇文章主要為大家介紹了Android開(kāi)發(fā)微信小程序路由跳轉(zhuǎn)方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪2022-04-04Android 6.0 藍(lán)牙搜索不到設(shè)備原因,MIUI權(quán)限申請(qǐng)機(jī)制方法
今天小編就為大家分享一篇Android6.0 藍(lán)牙搜索不到設(shè)備原因,MIUI權(quán)限申請(qǐng)機(jī)制方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07Android編程單擊圖片實(shí)現(xiàn)切換效果的方法
這篇文章主要介紹了Android編程單擊圖片實(shí)現(xiàn)切換效果的方法,以實(shí)例形式分析了Android布局及切換功能的具體實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10Android?掃碼槍輸入時(shí)屏蔽軟鍵盤和頂部狀態(tài)欄的解決方案
在Android設(shè)備上,使用掃碼槍時(shí)常遇到軟鍵盤和頂部狀態(tài)欄顯示問(wèn)題,本文介紹了在Android 7.1.2版本上,如何通過(guò)設(shè)置inputType為none屏蔽軟鍵盤,以及通過(guò)hideStatusBar和NoActionBar方法隱藏頂部狀態(tài)欄,以優(yōu)化掃碼槍使用界面,這些方法有助于提升使用掃碼槍場(chǎng)景的用戶體驗(yàn)2024-10-10Android?RecyclerView使用ListAdapter高效刷新數(shù)據(jù)的操作方法
這篇文章主要介紹了Android?RecyclerView使用ListAdapter高效刷新數(shù)據(jù),本次也是介紹了用另外一種方法來(lái)實(shí)現(xiàn)RecyclerView高效刷新數(shù)據(jù)的功能,需要的朋友可以參考下2022-10-10