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 frequently used components: Seekbar and Ratingbar. * 2, the function of the progress bar and how to use: * progress bar is often used to show the user a percentage of time-consuming operation completed, the progress bar can dynamically display the progress of the run * so avoid long time to run a time-consuming operation, let the user feel that the program is out of response. * Android support for example the following style of progress bar. The Style property enables you to specify a ProgressBar for the * @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 loop progress bar * @android: Style/widget.progressbar.small-----------Small Loop progress bar * @ Android:style/widget.progressbar.small.inverse---small loop progress bar * 3, ProgressBar frequently used XML attributes: * 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 track of the progress bar to the corresponding Drawable object * Android:indeterminate---------This property set to true. Set the progress bar to not accurately display the running progress * android:indeterminatedrawable-set the Drawable object to draw a progress bar that does not show the progress of the run * Android: indeterminateduration-set the duration of an imprecise display of running progress * android:progressdrawable the drawing form of the track used to specify the progress bar, which can refer to the* A Layerdrawable object (this object can be configured with the <layer-list> element in the XML file) * 4, ProgressBar provides the following two methods to manipulate progress * setprogress (int)-- -Set the percentage of progress to complete * Incrementprogressby (int)---Set the progress bar's progress to add or decrease. Progress is added * when the number of participants is positive, and progress is reduced when the number of participants 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 filling an array of length 100 private int [] data=new int[100];p rivate int hasdata=0;//record ProgressBar completion progress 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 run task new thread () {public void run () {status<100) {//Get complete percent of 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 complete"/> <!--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
Part of the Androidui ProgressBar