Progress bar of Android-android learning journey)
ProgressBar Introduction
ProgressBar is a common Ui used to display the progress of complex operations and provide better user response. Use setProgress () incrementProgressBy () to set the progress and display progress to increase or decrease. A positive value indicates an increase, and a negative value indicates a decrease.
ProgressBar Style
ProgressBar
Code example layout code
Subject Code
package peng.liu.testview;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.widget.ProgressBar;public class MainActivity extends Activity { private int[] data = new int[100]; int hasData = 0; int status = 0; ProgressBar bar,bar2; Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if(msg.what == 0x123){ bar.setProgress(status); bar2.setProgress(status); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); bar = (ProgressBar) findViewById(R.id.bar); bar2 = (ProgressBar) findViewById(R.id.bar2); new Thread(){ @Override public void run() { if(status < 100){ status = dowork(); handler.sendEmptyMessage(0x123); } } }; } public int dowork(){ data[hasData++] = (int) (Math.random()*100); try{ Thread.sleep(100); } catch (Exception e){ e.printStackTrace(); } return hasData; }}