Learning from the school network. Set a few buttons to update the progress bar manually, understand the next.
The code that goes straight to the simple progress bar is not deleted. First
The figure is not a little big ... Never mind...
Go ahead and set up the Main.xml file.
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <ProgressBarAndroid:id= "@+id/progressbar2"style= "? Android:attr/progressbarstylelarge"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /> <ProgressBarAndroid:id= "@+id/progressbar1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /><!--Central does not set - <ProgressBarAndroid:id= "@+id/progressbar3"style= "? Android:attr/progressbarstylesmall"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /> <ProgressBarandroid:secondaryprogress= " the"android:progress= "Ten"Android:max= "+"Android:id= "@+id/horiz"style= "? Android:attr/progressbarstylehorizontal"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" /> <ButtonAndroid:id= "@+id/add"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Add" /> <ButtonAndroid:id= "@+id/reduce"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "reduce" /> <ButtonAndroid:id= "@+id/reset"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Reset" /> <TextViewAndroid:id= "@+id/text"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "TextView" /></LinearLayout>
There is a lump of unnecessary progress bar in the middle of the lazy delete,,,
Then set the main file.
PackageCom.example.deemo;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.view.Window;ImportAndroid.widget.Button;ImportAndroid.widget.ProgressBar;ImportAndroid.widget.TextView; Public classMainactivityextendsActivityImplementsOnclicklistener {PrivateProgressBar Progress; PrivateButton add; PrivateButton reduce; PrivateButton Reset; PrivateTextView text; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //Enable window features to enable with progress and without progressrequestwindowfeature (window.feature_progress); Requestwindowfeature (window.feature_indeterminate_progress); Setcontentview (R.layout.main); //show two progress barsSetprogressbarvisibility (true); Setprogressbarindeterminatevisibility (false); Setprogress (9999);//progress of the straight progress bar, the maximum amount is 10000init (); } Private voidInit () {Progress=(ProgressBar) Findviewbyid (R.id.horiz); Add=(Button) Findviewbyid (R.id.add); Reduce=(Button) Findviewbyid (r.id.reduce); Reset=(Button) Findviewbyid (R.id.reset); Text=(TextView) Findviewbyid (R.id.text); intFrist = Progress.getprogress ();//getprogress () get the first progress bar intSecond=progress.getsecondaryprogress ();//get the second progress bar intmax = Progress.getmax ();//Get maximum ProgressText.settext ("First Progress percent" + (int) (frist/(float) + "% second progress percent" + (max*100) + (int) (Second/(float) max*100) + "%"); //Progress TipsAdd.setonclicklistener ( This);//setting up the monitorReduce.setonclicklistener ( This); Reset.setonclicklistener ( This); } @Override//Listen for event logic Public voidOnClick (View v) {//TODO auto-generated Method Stub Switch(V.getid ()) { Caser.id.add:{Progress.incrementprogressby (10);//increase the first progress of 10Progress.incrementsecondaryprogressby (10);//increase the second progress of 10 Break; } Caser.id.reduce:{Progress.incrementprogressby (-10);//reduce the first progress of 10Progress.incrementsecondaryprogressby (-10);//reduce the second progress of 10 Break; } Caser.id.reset:{progress.setprogress (10); Progress.setsecondaryprogress (20); Break; } } //every click to complete the dynamic updateText.settext ("First Progress percent" + (int) (Progress.getprogress ()/(float) Progress.getmax () *100) + "% second progress percent" + (int) (Progress.getsecondaryprogress ()/(float) Progress.getmax () *100) + "%"); }; }
Similarly, there are three progress bars that are extra.
Then click Add,reduce to play ♂ and get the progress bar.
Manually increase or decrease the progress bar