Progress bar (Progressbar)

Source: Internet
Author: User

Progress bar (Progressbar)

Provide some of the following styles to change the appearance of the progress bar

@android: Style/widget.progressbar.horizontal (horizontal progress bar)

@android: style/widget.progressbar.inverse (normal size ring progress bar)

@android: Style/widget.progressbar.large (large loop 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)

Common Properties:

Max: Set the maximum value of the progress bar

Progress: Sets the progress value for which the progress bar has completed

Progressdrawable: The Drawable object that sets the track for the progress bar (is an XML file)

Below we look directly at the code:

1.Activity

//progress bar Public classProgressbaractivityextendsActivity {PrivateProgressBar ProgressBarDefaultStyle1; PrivateProgressBar ProgressBarDefaultStyle2; Privatebutton button; PrivateHandler Handler =NewHandler () { Public voidhandlemessage (Message msg) {intFlag =Msg.arg1; if(Flag <= 100) {progressbardefaultstyle1.setprogress (flag); }            if(Flag <= 200) {progressbardefaultstyle2.setprogress (flag/2); }            if(flag==201) {progressbardefaultstyle1.setprogress (0); Progressbardefaultstyle2.setprogress (0); Button.setenabled (true);            Timertask.cancel ();    }        }    }; PrivateTimer timer =NewTimer (); PrivateSendmsgtimertask TimerTask =NewSendmsgtimertask (); @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.progress_bar); ProgressBarDefaultStyle1=(ProgressBar) Findviewbyid (r.id.progressbardefaultstyle1id); ProgressBarDefaultStyle2=(ProgressBar) Findviewbyid (R.ID.PROGRESSBARDEFAULTSTYLE2ID); Button=(Button) Findviewbyid (R.id.buttonid); Button.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {button.setenabled (false); Timer.schedule (TimerTask,5, 100);            }        }); }        classSendmsgtimertaskextendstimertask{intFlag = 0;  Public voidrun () {Message msg=NewMessage (); Msg.arg1= ++Flag;            Handler.sendmessage (msg); LOG.I ("Msg.arg1", "Send message:" +msg.arg1); }} @Overrideprotected voidOnDestroy () {Super. OnDestroy ();    Timer.cancel (); }    }

2.xml Layout file

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:padding= "5DP" > <!--define a normal-sized circular progress bar--<ProgressBar Android:id= "@+id/progressbarinversestyleid"style= "@android: Style/widget.progressbar.inverse"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"/> <!--define a large circular progress bar--<ProgressBar Android:id= "@+id/progressbarlargestyleid"style= "@android: Style/widget.progressbar.large"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@id/progressbarinversestyleid"/> <!--define a large circular progress bar-<ProgressBar Android:id= "@+id/progressbarlargeinversestyleid"style= "@android: Style/widget.progressbar.large.inverse"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@id/progressbarlargestyleid"/> <!--define a small loop progress bar-<ProgressBar Android:id= "@+id/progressbarsmallstyleid"style= "@android: Style/widget.progressbar.small"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@id/progressbarlargeinversestyleid"/> <!--define a small loop progress bar-<ProgressBar Android:id= "@+id/progressbarsmallinversestyleid"style= "@android: Style/widget.progressbar.small.inverse"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@id/progressbarsmallstyleid"/> <!--define a default style of horizontal progress bar--<ProgressBar Android:id= "@+id/progressbardefaultstyle1id"style= "@android: Style/widget.progressbar.horizontal"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_below= "@id/progressbarsmallinversestyleid"Android:max= "/>" <!--defines a horizontal progress bar for a specified style--<!--Bar_state is a picture state file---<ProgressBar Android:id= "@+id/progressbardefaultstyle2id"style= "@android: Style/widget.progressbar.horizontal"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_below= "@id/progressbardefaultstyle1id"Android:max= "100"android:progressdrawable= "@drawable/bar_state"/> <Button Android:id= "@+id/buttonid"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@id/progressbardefaultstyle2id"Android:text= "Analog time-consuming operation"/></relativelayout>

3. The layout file of the progress bar

<?xml version= "1.0" encoding= "Utf-8"? ><layer-list xmlns:android= "http://schemas.android.com/apk/res/ Android >    <!--define the background of the track--    <item android:id= "@android: Id/background" android:drawable= "@ Drawable/no "/>    <!--defining a successful image of the track--    <item android:id=" @android: id/progress "android:drawable=" @ Drawable/yes "/></layer-list>

4. Effect Display Chart

Progress bar (Progressbar)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.