這篇文章主要介紹Android UI控件之ProgressBar進(jìn)度條的實(shí)現(xiàn)方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),怒江州網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:怒江州等地區(qū)。怒江州做網(wǎng)站價(jià)格咨詢:13518219792
具體實(shí)現(xiàn)首先看布局文件:
之后是MainActivity
package com.kiritor.ui_progressbar; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.ProgressBar; public class MainActivity extends Activity implements Runnable { private ProgressBar bar = null; private Thread thread = null;// 聲明一個(gè)線程 private boolean stateChange; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bar = (ProgressBar) findViewById(R.id.progressBar3); thread = new Thread(this); thread.start(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void run() { while (true) { int current = bar.getProgress();// 得到當(dāng)前進(jìn)度值 int currentMax = bar.getMax();// 得到進(jìn)度條的最大進(jìn)度值 //int secCurrent = bar.getSecondaryProgress();// 得到底層當(dāng)前進(jìn)度值 // 以下代碼實(shí)現(xiàn)進(jìn)度值越來(lái)越大,越來(lái)越小的一個(gè)動(dòng)態(tài)效果 if (stateChange == false) { if (current >= currentMax) { stateChange = true; } else { // 設(shè)置進(jìn)度值 bar.setProgress(current + 1); // 設(shè)置底層進(jìn)度值 bar.setSecondaryProgress(current + 1); } } else { if (current <= 0) { stateChange = false; } else { bar.setProgress(current - 1); bar.setSecondaryProgress(current - 1); } } try { Thread.sleep(50); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
以上是“Android UI控件之ProgressBar進(jìn)度條的實(shí)現(xiàn)方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!