Read "Android from getting Started to mastering" (17)--progress bar

Source: Internet
Author: User

Progress bar (ProgressBar)

Java.lang.Object;
Android.view.View;
Android.widget.ProgressBar;

ProgressBar class method



ProgressBar Demo sample

Full project:http://download.csdn.net/detail/sweetloveft/9416791

Let's learn the most frequently used methods in this class. Mainly Setmax and setprogress and other methods.

1.mainactivity.java

Package Com.sweetlover.activity;import Com.sweetlover.progressbar.r;import Android.app.activity;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.Button; Import Android.widget.progressbar;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); final ProgressBar progresshorizontal = (ProgressBar) Findviewbyid (r.id.progress_horizontal)        ;        Setprogress (progresshorizontal.getprogress () * 100);                Setsecondaryprogress (progresshorizontal.getsecondaryprogress () * 100);        Button button = (button) Findviewbyid (r.id.increase); Button.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {Progresshorizont                Al.incrementprogressby (1); Title progress is in range 0..10000 setprogress (* Progresshorizontal.getprogress ());        }        });        Button = (button) Findviewbyid (r.id.decrease); Button.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {Progresshorizont                Al.incrementprogressby (-1);            Title progress is in range 0..10000 setprogress (+ progresshorizontal.getprogress ());        }        });        Button = (button) Findviewbyid (r.id.increase_secondary); Button.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {Progresshorizont                Al.incrementsecondaryprogressby (1); Title progress is in range 0..10000 setsecondaryprogress (+ progresshorizontal.getsecondaryprogress ()            );        }        });        Button = (button) Findviewbyid (r.id.decrease_secondary); Button.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {ProgressHorizontal.incrementsecondaryprogressby (-1); Title progress is in range 0..10000 setsecondaryprogress (+ progresshorizontal.getsecondaryprogress ()            ); }        });}}

2.activity_main.xml

<?

XML version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android "Android:orientation=" vertical "android:layout_width=" match_parent "android:layout_height=" Wrap_content "Android oid:padding= "30DP" > <progressbar android:id= "@+id/progress_horizontal" style= "?

Android:attr/progressbarstylehorizontal "android:layout_width=" 200dip "android:layout_height=" Wrap_content " android:layout_gravity= "center" android:max= "android:progress=" android:secondaryprogr ess= "/> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content " android:layout_gravity= "center" android:layout_margintop= "20DP" android:text= "@string/normal"/> &L T LinearLayout android:orientation= "Horizontal" android:layout_width= "Match_parent" Android:layout_heig ht= "wrap_content" android:gravity= "center" android:layout_margintop= "20DP" > <button Android:id= "@+id/decrease" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "@string/decrease"/> <button android:id= "@+id/increase" Andro Id:layout_width= "Wrap_Content "android:layout_height=" wrap_content "android:text=" @string/increase "/> </linearla yout> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" and roid:layout_gravity= "center" android:layout_margintop= "20DP" android:text= "@string/custom"/> <line Arlayout android:orientation= "Horizontal" android:layout_width= "Match_parent" android:layout_height= " Wrap_content "android:gravity=" center "android:layout_margintop=" 20DP "> <button and Roid:id= "@+id/decrease_secondary" android:layout_width= "wrap_content" android:layout_height= "Wrap_co Ntent "android:text=" @string/decrease "/> <button android:id=" @+id/increase_secondary " Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "@s Tring/increase "/> </LinearLayout></LinearLayout>

3.strings.xml

<resources>    <string name= "app_name" >ProgressBar</string>    <string name= "normal" > Default progress bar </string>    <string name= "Decrease" > Lower </string>    <string name= "Increase" > Add </string>    <string name= "Custom" > self-defined progress bar </string>    </resources>

4.androidmanifest.xml

<manifest xmlns:android= "http://schemas.android.com/apk/res/android"    package= "Com.sweetlover.progressbar "    android:versioncode=" 1 "    android:versionname=" 1.0 ">    <uses-sdk        android:minsdkversion=" 8 "        android:targetsdkversion= "/>"    <application        android:allowbackup= "true"        android:icon= "@ Drawable/ic_launcher "        android:label=" @string/app_name "        android:theme=" @style/apptheme ">        < Activity android:name= "Com.sweetlover.activity.MainActivity" >            <intent-filter>                <action Android:name= "Android.intent.action.MAIN"/>                <category android:name= "Android.intent.category.LAUNCHER "/>            </intent-filter>        </activity>    </application></manifest>

Read "Android from getting Started to mastering" (17)--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.