1. Introduction
Progress is the progress bar for loading progress.
2. Build
The built interface increases the progress bar when pressing the + Key button, and the progress bar is reduced when the-button is pressed.
<relativelayout 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:paddingbottom= "@dimen/activity_vertical_margin"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= "Example.progressbar.Activity1" >
<progressbar
android:id= "@+id/progressbar1"
style= "? Android:attr/progressbarstylehorizontal"
android:layout_width= "Fill_parent"
android:layout_height= "60DP"
android:progress= "Ten" //Set the initial length of the progress bar to 10%
android:layout_alignparentstart= "true"
android:layout_alignparenttop= "true"/>
<progressbar
android:id= "@+id/progressbar2"
style= "? Android:attr/progressbarstylelarge"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/progressbar1"
android:layout_centerhorizontal= "true"
android:layout_margintop= "47DP"/>
<button
android:id= "@+id/button1"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/progressbar2"
android:layout_margintop= "72DP"
android:layout_tostartof= "@+id/progressbar2"
android:text= "@string/bt1"/>
<button
android:id= "@+id/button2"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_alignbottom= "@+id/button1"
android:layout_toendof= "@+id/progressbar2"
android:text= "@string/bt2"/>
</RelativeLayout>
3. Code
Public class Activity1 extends Activity implements Onclicklistener{
Button b1,b2;
ProgressBar PB;
@Override
Public void OnClick (View v) {
//To monitor the button, by ID to match
if (V.getid () ==r.id.button1) {
//Getporgress () Gets the length of the initial progress bar, multiplied by 2, increments one time, and then sets the progress bar by Setprogress ()
pb.setprogress ((int) (pb.getprogress ()));
}
else{
pb.setprogress ((int) (pb.getprogress () *0.6));
}
}
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.LAYOUT.ACT1);
b1= (Button) Findviewbyid (R.id.button1);
B2= (Button) Findviewbyid (R.id.button2);
pb= (ProgressBar) Findviewbyid (R.ID.PROGRESSBAR1);
//Set listener
B1.setonclicklistener (this);
B2.setonclicklistener (this);
}
4. Effects
Application of Android Development--progressbar