Android 14 progress bar and drag bar

Source: Internet
Author: User

Progress bar:

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">    <ProgressBarDefault progress bar Android:id= "@+id/pb1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"/>    <ProgressBarAndroid:id= "@+id/pb2"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"style= "@android: Style/widget.progressbar.horizontal"Android:max= "+"maximum value is android:progress= "+"/>the initial value is<ButtonAndroid:id= "@+id/btndownload"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Download File"/></LinearLayout>
 Packagecom.sxt.day03_07;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.SystemClock;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.ProgressBar; Public classMainactivityextendsActivity {ProgressBar mprogressbar; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Initview ();    Setlistener (); }    Private voidSetlistener () {Findviewbyid (r.id.btndownload). Setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {NewThread () {//Open A thread, then the progress bar work, does not affect the main thread of the work, if not multi-threading the progress bar to work when you click somewhere else there will be problems                     Public voidrun () { for(inti=1;i<=100;i++) {mprogressbar.setprogress (i); Systemclock.sleep (20);//Systemclock.sleep (20) is an Android pause, and the progress bar changes to keep the current thread dormant for 10 milliseconds                        }                    };            }.start ();    }        }); }    Private voidInitview () {Mprogressbar=(ProgressBar) Findviewbyid (R.ID.PB2); Mprogressbar.setprogress (0); }}

Drag the bar:

<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <SeekBarAndroid:id= "@+id/seekbar"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:max= "+"android:progress= " the"/></Relativelayout>
 Packagecom.sxt.day03_08;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.widget.SeekBar;ImportAndroid.widget.SeekBar.OnSeekBarChangeListener; Public classMainactivityextendsActivityImplementsonseekbarchangelistener{intmprogress;//represents the current progress value of Seekbar@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); SeekBar SeekBar=(SeekBar) Findviewbyid (R.id.seekbar); Seekbar.setonseekbarchangelistener ( This);//Add a drag listener to Seekbar} @Override Public voidOnprogresschanged (SeekBar SeekBar,intProgress,BooleanFromuser) {//This function is always called in drag, Fromuser is true for touch operation, progress represents the current drag value,mprogress=progress; LOG.I ("Main", "progress=" +progress); } @Override Public voidOnstarttrackingtouch (SeekBar SeekBar) {//Start Drag functionLOG.I ("main", "Start dragging Seekbar"); } @Override Public voidOnstoptrackingtouch (SeekBar SeekBar) {//End Drag functionLOG.I ("main", "End drag Seekbar"); }}

Android 14 progress bar and drag 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.