Package com.gc.progressbar;/* * 1, ProgressBar component is also a set of important components, ProgressBar itself represents the progress bar component, * It also derives two commonly used components: Seekbar and Ratingbar. * 2, the function and usage of the progress bar: * The progress bar is typically used to show the user a percentage of time-consuming operations completed, and the progress bar can dynamically show progress * thus avoiding long periods of time to perform a time-consuming operation, the user feels the program is out of response. * Android supports the following style of the progress bar, through the style property can be specified for ProgressBar style * @android: style/widget.progressbar.horizontal-----Horizontal progress bar * @ Android:style/widget.progressbar.inverse--------Normal-sized circular progress bar * @android: style/ Widget.ProgressBar.Large----------Large Circular progress bar * @android: style/widget.progressbar.large.inverse---Large circular progress bar * @android: Style/widget.progressbar.small-----------Small Loop progress bar * @android: Style/widget.progressbar.small.inverse---small loop progress bar * 3, ProgressBar Common XML Properties: * Android:max-------------------Set the maximum value of the progress bar * Android:progress--------------Set the completed progress value for the progress bar * android:progressdrawable------Set the Drawable object for the track of the progress bar * Android:indeterminate---------This property to true to set the progress bar to show the progress without accuracy * android:indeterminatedrawable-set the Drawable object to draw a progress bar that does not show progress * android:indeterminateduration-set the duration of the progress not accurately displayed * Android: Progressdrawable the drawing form of the track used to specify the progress bar, which can be specified as a layerdrawabA reference to the Le object (which can be configured with the <layer-list> element in an XML file) * 4, ProgressBar provides the following two ways to manipulate progress * setprogress (int)---Set percent complete of progress * Incrementprogressby (int)---to set the progress bar to an increase or decrease in progress. Progress is increased when the parameter is positive *, and progress is reduced when the parameter is negative. */import android.os.bundle;import android.os.handler;import Android.os.message;import android.app.Activity;import Android.view.menu;import android.widget.progressbar;/** * * @author Android General * */public class Mainactivity extends Activ ity {//The program simulates an array with a fill length of 100 private int [] data=new int[100];p rivate int hasdata=0;//Record The completion progress of the ProgressBar private int status=0; Private ProgressBar bar,bar2;//creates a handlerhandler mhandler=new Handler () {@Overridepublic void handlemessage that is responsible for the progress of the update ( Message msg) {//TODO auto-generated method stub//indicates that the message is sent by the program if (msg.what==0x111) {bar.setprogress (status); Bar2.setprogress (status);}}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); bar= (ProgressBar) Findviewbyid (R.id.bar); bar2= (ProgressBar) Findviewbyid (r.id.BAR2);//start thread to perform task new thread () {public void run () {while (status<100) {//Get percent complete for time-consuming Operation Status=dowork ();// Send Message Mhandler.sendemptymessage (0x111);}}. Start ();} Simulates a time-consuming operation public int doWork () {//Array element assignment data[hasdata++]= (int) (Math.random () *100); Try{thread.sleep (100);} catch (Interruptedexception e) {e.printstacktrace ();} return hasData;}}
Layout file:
<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:orien tation= "vertical" > <linearlayout android:orientation= "Horizontal" android:layout_width= "match_p Arent "android:layout_height=" wrap_content "> <!--define a large circular progress bar--<progressbar Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" style= "@android: St Yle/widget.progressbar.large "/> <!--define a medium-sized circular progress bar--<progressbar and Roid:layout_width= "Wrap_content" android:layout_height= "Wrap_content"/> <!--define a small loop progress Bar--<progressbar android:layout_width= "wrap_content" android:layout_height= "Wrap_con Tent "style=" @android: STYLE/WIDGET.PRogressbar.small "/> </LinearLayout> <textview android:layout_width=" Fill_parent " android:layout_height= "wrap_content" android:text= "task completion progress"/> <!--define a horizontal progress bar--<pro Gressbar android:id= "@+id/bar" android:layout_width= "fill_parent" android:layout_height= "Wrap_conten T "android:max=" "style=" @android: Style/widget.progressbar.horizontal "/> <!--define a horizontal progress bar, and change the track appearance--<progressbar android:id= "@+id/bar2" android:layout_width= "Fill_parent" Android: layout_height= "Wrap_content" android:max= "android:progressdrawable=" @drawable/my_bar "style=" @an Droid:style/widget.progressbar.horizontal "/></linearlayout>
Reprint Please specify source: http://blog.csdn.net/android_jiangjun/article/details/25555633