Android 20th Lesson--progressbar

Source: Internet
Author: User

<LinearLayoutxmlns: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:orientation= "vertical"Tools:context= "Com.example.progressbar.mainactivity$placeholderfragment" >    <LinearLayoutandroid:orientation= "Horizontal"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content">    <!--define a large circular progress bar -    <ProgressBarstyle= "? Android:attr/progressbarstylelarge"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" />  <!--define a normal circular progress bar -    <ProgressBarAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" />  <!--Define a small loop progress bar -    <ProgressBarstyle= "? Android:attr/progressbarstylesmall"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content" /></LinearLayout>    <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "@string/progress"         />    <!--Horizontal progress bar -    <ProgressBarAndroid:id= "@+id/bar1"style= "? Android:attr/progressbarstylehorizontal"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:max= "+" />    <!--Customizing the horizontal progress bar -    <ProgressBarAndroid:id= "@+id/bar"style= "? Android:attr/progressbarstylehorizontal"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:progressdrawable= "@drawable/my_bar"Android:max= "+" /></LinearLayout>
<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android" >    <!--defining the track background -    <ItemAndroid:id= "@android: Id/background"android:drawable= "@drawable/no"></Item><ItemAndroid:id= "@android: id/progress"android:drawable= "@drawable/ok"></Item></layer-list>
 PackageCom.example.progressbar;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.os.Message;ImportAndroid.widget.ProgressBar; Public classMainactivityextendsActivity {Private int[] Data=New int[100]; intHasdata=0; //Record Completion Progress    intStatus=0;    ProgressBar bar,bar1; //create a handler that is responsible for updating progressHandler mhandler=NewHandler () { Public voidhandlemessage (Message msg) {if(msg.what==0x111) {bar.setprogress (status);                Bar1.setprogress (status);    }            }            }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); Bar=(ProgressBar) Findviewbyid (R.id.bar); Bar1=(ProgressBar) Findviewbyid (R.ID.BAR1); NewThread () { Public voidrun () { while(status<100){                //get percent complete for time-consuming operationsstatus=doWork (); //Send MessageMhandler.sendemptymessage (0x111);    }}}.start (); }     Public intdoWork () {Data[hasdata++]=(int) (Math.random () *100); Try{Thread.Sleep (100); } Catch(interruptedexception e) {e.printstacktrace (); }        returnHasData; }}

Only in the use of the thread, handler knowledge.

Android 20th Lesson--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.