Android 進(jìn)度條自動(dòng)前進(jìn)效果的實(shí)現(xiàn)代碼
今天給大家分享進(jìn)度條自動(dòng)前進(jìn)功能的實(shí)現(xiàn),先給大家分享實(shí)現(xiàn)效果圖,感覺不錯(cuò)可以參考實(shí)現(xiàn)代碼。
效果如下圖:
首先布局要設(shè)置進(jìn)度條最大值:
<ProgressBar android:android:layout_width='400dp' android:layout_centerHorizontal='true' android:layout_centerVertical='true' android:progressDrawable='@drawable/jian' //漸變 android:max='100' //設(shè)置最大值為100 android:layout_height='25dp' />
主要代碼:
final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { proes++; bar1.setProgress(proes); //進(jìn)度條進(jìn)度 } }); } },100,100); //間隔時(shí)間(單位為毫秒)
所有代碼:
int proes = 0; //進(jìn)度條進(jìn)度值 ProgressBar bar1; Button but1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bar1 = findViewById(R.id.pro1); but1 = findViewById(R.id.but1); final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { proes++; //增加進(jìn)度值 if(proes==100){ timer.cancel(); //當(dāng)proes到最大值時(shí)停止增加 }else{ bar1.setProgress(proes); // proes當(dāng)前進(jìn)度 } } }); } },100,100); //間隔時(shí)間(單位為毫秒) }}
總結(jié)
到此這篇關(guān)于Android 進(jìn)度條自動(dòng)前進(jìn)效果的實(shí)現(xiàn)代碼的文章就介紹到這了,更多相關(guān)Android 進(jìn)度條自動(dòng)前進(jìn)內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP基礎(chǔ)入門第八篇(ASP內(nèi)建對(duì)象Application和Session)2. PHP循環(huán)與分支知識(shí)點(diǎn)梳理3. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)4. 解析原生JS getComputedStyle5. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?6. 小技巧處理div內(nèi)容溢出7. jsp實(shí)現(xiàn)登錄驗(yàn)證的過濾器8. 概述IE和SQL2k開發(fā)一個(gè)XML聊天程序9. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法10. ASP中格式化時(shí)間短日期補(bǔ)0變兩位長(zhǎng)日期的方法
