Android之進度條2

來源:互聯網
上載者:User

標籤:

我之前有寫過一篇“Android之進度條1”,那個是條形的進度條(顯示數字進度),這次實現圓形進度條。

點擊查看Android之進度條1:http://www.cnblogs.com/caidupingblogs/p/5102745.html>

MainActivity繼承Activity實現Runnable介面:

package com.cdp.progressbar; import android.app.Activity;import android.os.Bundle;import android.widget.ProgressBar;    //使用Runnable介面public class MainActivity extends Activity implements Runnable {    //聲明一條線程    private Thread th ;      //聲明一個進度條對象     private ProgressBar pb ;         //標識進度值最大最小的狀態    private boolean stateChage;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);         //執行個體進度條對象        pb = (ProgressBar)findViewById(R.id.porb);         //執行個體線程對象        th = new Thread(this);        //啟動線程        th.start();    }     @Override    public void run() {//實現Runnable介面抽象函數        while(true){             //得到當前進度值            int current = pb.getProgress();            //得到進度條的最大進度值               int currentMax = pb.getMax();            //得到底層當前進度值                 int secCurrent = pb.getSecondaryProgress();            //以下代碼實現進度值越來越大,越來越小的一個動態效果            if(stateChage==false){                 if(current>=currentMax){                     stateChage=true;                 }else{                    //設定進度值                    pb.setProgress(current+1);                    //設定底層進度值                    pb.setSecondaryProgress(current+1);                }            }else{                if(current<=0){                     stateChage=false;                 }else{                    pb.setProgress(current-1);                    pb.setSecondaryProgress(current-1);                }            }            try {                Thread.sleep(50);            } catch (InterruptedException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }        }    }}

run:

Android之進度條2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.