Android ProgressBar level progress bar

Source: Internet
Author: User

<?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/ok"/> <!--define the finished part of the track style-<item android:id="@android: Id/progress"android:drawable="@drawable/no"/></layer-list>


My_bar.xml//Configuration progress bar picture
@drawable/ok @drawable/no to save the picture in the Drawable folder

Progress bar configuration in Layout files

<progressbar <!--Use the system default-->android:id= "@+id/bar" android:layout_width= "Fill_parent" Android:layout_ height= "Wrap_content" android:max= "style=" @android: Style/widget.progressbar.horizontal "/><!-- Define a horizontal progress bar and change the track appearance--><progressbar  <!--custom-->android:id= "@+id/bar2" android:layout_width= "Fill_ Parent "android:layout_height=" wrap_content "android:max=" android:progressdrawable= "@drawable/my_bar"  <!--This is the configuration file above-->style= "@android: Style/widget.progressbar.horizontal"/>

Call in activity

1  Public classProgressbartest extends Activity2 {3     //The program simulates populating an array with a length of 1004     Private int[] data =New int[ -];5     intHasData =0;6     //record the completion progress of ProgressBar7     intStatus =0; 8 @Override9      Public voidonCreate (Bundle savedinstancestate)Ten     { One super.oncreate (savedinstancestate); A Setcontentview (r.layout.main); -Final ProgressBar bar =(ProgressBar) Findviewbyid (R.id.bar); -Final ProgressBar bar2 =(ProgressBar) Findviewbyid (R.ID.BAR2); the         //create a handler that is responsible for the progress of the update -Final Handler Mhandler =NewHandler () -         { - @Override +              Public voidhandlemessage (Message msg) -             { +                 //indicates that the message was sent by the program.  A                 if(Msg.what = =0x111) at                 { - bar.setprogress (status); - bar2.setprogress (status); -                 } -             } -         }; in         //to start a thread to perform a task -         NewThread () to         { +              Public voidRun () -             { the                  while(Status < -) *                 { $                     //get percent complete for time-consuming operationsPanax NotoginsengStatus =doWork (); -                     //send message to Handler theMessage m =NewMessage (); +M.what =0x111; A                     //Send Message the Mhandler.sendmessage (m); +                 } -             } $ }.start (); $     } -     //simulates a time-consuming operation.  -      Public intdoWork () the     { -         //Assigning a value to an array elementWuyidata[hasdata++] = (int) (Math.random () * -); the         Try -         { WuThread.Sleep ( -); -         } About         Catch(interruptedexception e) $         { - e.printstacktrace (); -         } -         returnHasData; A     } +}

Android ProgressBar level progress bar

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.