Android ProgressBar and Seekbar's small demo

Source: Internet
Author: User

This shows the progress bar of the Android ProgressBar, because the Android bar progress bar is initially static and not like a circular progress bar is dynamic;

And Seekbar is the drag bar of Android, use the scene such as music or video playback in the time ~ ~ ~

XML layout file (Note that the style type to be selected when using the bar progress bar is

"? Android:attr/progressbarstylehorizontal"

):

<Relativelayoutxmlns: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=". Mainactivity "Android:background= "#BBBB0000">    <ProgressBarAndroid:id= "@+id/pb"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"style= "? Android:attr/progressbarstylehorizontal"Android:max= "+"android:progress= " the"android:secondaryprogress= "The "/>    <SeekBarAndroid:id= "@+id/seekbar"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_below= "@id/pb"Android:text= "Drag"/></Relativelayout>

Mainactivity.java file:

Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.widget.ProgressBar;ImportAndroid.widget.SeekBar;ImportAndroid.widget.SeekBar.OnSeekBarChangeListener; Public classMainactivityextendsActivityImplementsRunnable, Onseekbarchangelistener {PrivateProgressBar PB; PrivateThread th; BooleanStateChange;    SeekBar SeekBar; PrivateString tag = "SEEKBAR"; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); PB=(ProgressBar) Findviewbyid (R.ID.PB); Seekbar=(SeekBar) Findviewbyid (R.id.seekbar); Seekbar.setonseekbarchangelistener ( This); Th=NewThread ( This);    Th.start (); } @Override Public voidOnprogresschanged (SeekBar arg0,intArg1,Booleanarg2) {        //TODO auto-generated Method StubLOG.V (Tag, "Drag Change"); } @Override Public voidOnstarttrackingtouch (SeekBar arg0) {//TODO auto-generated Method StubLOG.V (Tag, "Change in"); } @Override Public voidOnstoptrackingtouch (SeekBar arg0) {//TODO auto-generated Method StubLOG.V (tag, "Stop changing"); } @Override Public voidrun () {//TODO auto-generated Method Stub         while(true){            intCurrent =pb.getprogress (); intCurrentmax =Pb.getmax (); intSeccurrent =pb.getsecondaryprogress (); if(StateChange = =false) {                if(Current <Currentmax) {pb.setprogress ( current+1); Pb.setsecondaryprogress ( current+1); }Else if(Current = =Currentmax) {StateChange=true; }            }            Else{                if(Current > 0) {pb.setprogress ( current-1); Pb.setsecondaryprogress ( current-1); }Else if(current = = 0) {StateChange=false; }            }            Try{Thread.Sleep (100); } Catch(Exception e) {//Todo:handle ExceptionE.printstacktrace (); }        }    }    }   

Run effect (the business code for the progress bar is the constant change in the simulation progress)

The picture can't actually upload today, wait for a while to fill up again.

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.