Basic use of the progress bar control, and use of the progress bar Control

Source: Internet
Author: User

Basic use of the progress bar control, and use of the progress bar Control
Basic usage of the progress bar Control

I. Introduction

 

 

Ii. Method

1) usage of progress bar

1. Create the ProgressBar control in the layout file.

<ProgressBar
>

Click "add progress:

Click the reduce progress button:

 

Code:

Fry. Activity01

1 package fry; 2 3 import com. example. ex26ProgressBar. r; 4 5 import android. app. activity; 6 import android. OS. bundle; 7 import android. view. view; 8 import android. view. view. onClickListener; 9 import android. widget. button; 10 import android. widget. progressBar; 11 12 public class Activity01 extends Activity implements OnClickListener {13/* 14 * progress bar usage Method 15*1. Create the ssssbar control in the layout file 16*2. Point the ProgressBar object to the ProgressBar control 17*3. Use getProgress () of the ProgressBar object () and setProgress () method to modify the progress 18*19 */20 private Button btn_addProgress; 21 private Button btn_minusProgress; 22 private ProgressBar pb_progressBar1; 23 private int progress; 24 @ Override25 protected void onCreate (Bundle savedInstanceState) {26 27 // TODO Auto-generated method stub28 super. onCreate (savedInstanceState); 29 setContentView (R. layout. activity01); 30 31 btn_addProgress = (Button) findViewById (R. id. btn_addProgress); 32 btn_minusProgress = (Button) findViewById (R. id. btn_minusProgress); 33 pb_progressBar1 = (ProgressBar) findViewById (R. id. pb_progressBar1); 34 35 btn_addProgress.setOnClickListener (this); 36 btn_minusProgress.setOnClickListener (this); 37 38} 39 @ Override40 public void onClick (View v) {41 // TODO Auto-generated method stub42 switch (v. getId () {43 case R. id. btn_addProgress: 44 if (progress <= 100) {45 progress = pb_progressBar1.getProgress (); 46 progress ++ = (int) (100*0.2); 47 pb_progressBar1.setProgress (progress ); 48} else progress = 100; 49 50 break; 51 case R. id. btn_minusProgress: 52 if (progress> = 0) {53 progress = pb_progressBar1.getProgress (); 54 progress-= (int) (100*0.2); 55 pb_progressBar1.setProgress (progress ); 56} else progress = 0; 57 break; 58 59 default: 60 break; 61} 62} 63}

/Ex26ProgressBar/res/layout/activity01.xml

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent" 5 android: orientation = "vertical"> 6 7 <! -- Style: Set the control style --> 8 <! -- Use? To reference things --> 9 <ProgressBar 10 style = "? Android: attr/progressBarStyleSmall "11 android: layout_width =" wrap_content "12 android: layout_height =" wrap_content "13/> 14 15 <ProgressBar 16 style = "? Android: attr/progressBarStyleLarge "17 android: layout_width =" wrap_content "18 android: layout_height =" wrap_content "19/> 20 21 22 <ProgressBar 23 style = "? Android: attr/progressBarStyleLargeInverse "24 android: layout_width =" wrap_content "25 android: layout_height =" wrap_content "26/> 27 28 <ProgressBar 29 style = "? Android: attr/progressBarStyleHorizontal "30 android: layout_width =" match_parent "31 android: layout_height =" wrap_content "32 android: progress =" 30 "33/> 34 35 <ProgressBar 36 android: id = "@ + id/pb_progressBar1" 37 style = "? Android: attr/progressBarStyleHorizontal "38 android: layout_width =" match_parent "39 android: layout_height =" wrap_content "40 android: progress =" 50 "41 android: secondaryProgress = "80" 42 android: layout_marginTop = "30dp" 43/> 44 45 <LinearLayout 46 android: layout_width = "match_parent" 47 android: layout_height = "wrap_content" 48 android: orientation = "horizontal" 49> 50 <Button 51 android: id = "@ + id/btn_addProgress" 52 android: layout_width = "wrap_content" 53 android: layout_height = "wrap_content" 54 android: text = "Progress added" 55 android: layout_weight = "1" 56/> 57 58 <Button 59 android: id = "@ + id/btn_minusProgress" 60 android: layout_width = "wrap_content" 61 android: layout_height = "wrap_content" 62 android: text = "Progress reduction" 63 android: layout_weight = "1" 64/> 65 66 </LinearLayout> 67 68 69 </LinearLayout>

 

4. Notes

1. Use the getProgress () and setProgress () Methods of the ProgressBar object to modify the progress.

Progress = pb_progressBar1.getProgress ();
Progress + = (int) (100*0.2 );
Pb_progressBar1.setProgress (progress );

2. If you encounter unknown controls and properties, you can use the set and get methods to see how to use them.

 

V. easy to make mistakes

 

Related Article

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.