Progress bar of the Android Control

Source: Internet
Author: User

The following describes ProgressBar in detail.

I. Description

The visual indicator in the progress of some operations shows the operation progress for the user, and it also has a secondary progress bar to display the intermediate progress, such as the progress in the buffer area of streaming media playback. A progress bar cannot be determined. In uncertain mode, the progress bar displays a circular animation. This mode is often used in applications. The length of a task is unknown.

Ii. Important XML attributes

Android: progressBarStyle: Default progress bar style

Android: progressBarStyleHorizontal: horizontal style

 

Iii. Important Methods

GetMax (): Maximum range of the returned progress bar

GetProgress (): returns the progress

GetSecondaryProgress (): returns the secondary progress

IncrementProgressBy (int diff): Specifies the increase progress.

IsIndeterminate (): indicates whether the progress bar is in uncertain mode.

SetIndeterminate (boolean indeterminate): sets the uncertain mode.

SetVisibility (int v): sets whether the progress bar is visible.

4. Important Events

OnSizeChanged (int w, int h, int oldw, int oldh): this event is triggered when the progress value changes.

V. Instances

1. layout File


[Html]
<? 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">
 
<ProgressBar android: id = "@ + id/progress_horizontal"
Style = "? Android: attr/progressBarStyleHorizontal"
Android: layout_width = "200dip"
Android: layout_height = "wrap_content"
Android: max = "100"
Android: progress = "50"
Android: secondaryProgress = "75"/>
 
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Default progress bar"/>
 
<LinearLayout
Android: orientation = "horizontal"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">
 
<Button android: id = "@ + id/decrease"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "reduce"/>
 
<Button android: id = "@ + id/increase"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "add"/>
 
</LinearLayout>
 
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Custom progress bar"/>
 
<LinearLayout
Android: orientation = "horizontal"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">
 
<Button android: id = "@ + id/decrease_secondary"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "second decrease"/>
 
<Button android: id = "@ + id/increase_secondary"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "added second"/>
 
</LinearLayout>
 
</LinearLayout>

<? 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">

<ProgressBar android: id = "@ + id/progress_horizontal"
Style = "? Android: attr/progressBarStyleHorizontal"
Android: layout_width = "200dip"
Android: layout_height = "wrap_content"
Android: max = "100"
Android: progress = "50"
Android: secondaryProgress = "75"/>

<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Default progress bar"/>

<LinearLayout
Android: orientation = "horizontal"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">

<Button android: id = "@ + id/decrease"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "reduce"/>

<Button android: id = "@ + id/increase"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "add"/>

</LinearLayout>

<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Custom progress bar"/>

<LinearLayout
Android: orientation = "horizontal"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">

<Button android: id = "@ + id/decrease_secondary"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "second decrease"/>

<Button android: id = "@ + id/increase_secondary"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "added second"/>

</LinearLayout>

</LinearLayout>

 

 

2. Java code


[Java]
Package wjq. WidgetDemo;
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. Window;
Import android. widget. Button;
Import android. widget. ProgressBar;
 
Public class ProgressBarDemo extends Activity {
 
/* (Non-Javadoc)
* @ See android. app. Activity # onCreate (android. OS. Bundle)
*/
@ Override
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );

RequestWindowFeature (Window. FEATURE_PROGRESS );
SetContentView (R. layout. probarpage );
SetProgressBarVisibility (true );

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 Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementProgressBy (1 );
// Title progress is in range 0 .. 10000
SetProgress (100 * progressHorizontal. getProgress ());
}
});
 
Button = (Button) findViewById (R. id. decrease );
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementProgressBy (-1 );
// Title progress is in range 0 .. 10000
SetProgress (100 * progressHorizontal. getProgress ());
}
});
 
Button = (Button) findViewById (R. id. increase_secondary );
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementSecondaryProgressBy (1 );
// Title progress is in range 0 .. 10000
SetSecondaryProgress (100 * progressHorizontal. getSecondaryProgress ());
}
});
 
Button = (Button) findViewById (R. id. decrease_secondary );
Button. setOnClickListener (new Button. OnClickListener (){
Public void onClick (View v ){
ProgressHorizontal. incrementSecondaryProgressBy (-1 );
// Title progress is in range 0 .. 10000
SetSecondaryProgress (100 * progressHorizontal. getSecondaryProgress ());
}
});

}
 
}

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.