Process entry ProgressBar can be used to display the current progress of an operation (such as downloading an object). The application can change the length of a process entry based on the Operation progress. The process bar in Android also supports a secondary progress bar to display the progress of any intermediate operation. For example, if you extract a file package, the main progress bar can display the decompression progress of the entire file package, the secondary progress bar displays the progress of the files being decompressed.
You can set the ProgressBar to "indeterminate" mode if you do not know the time required for the operation. At this time, the progress bar can display a rolling wheel or a horizontal progress bar.
Define ProgressBar in Layout, such:
[Html]
<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"/>
<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"/>
ProgressBar is displayed as a Spinning Wheel by default. If you want to use a horizontal progress bar, set its mode to progressBarStyleHorizontal. (Or style = "@ android: style/Widget. ProgressBar. Horizontal) if you need to specify the current progress value of the progress bar, you must use the Horizontal progress bar style.
Another common style is Widget. ProgressBar. Small, which is represented as a Small rotating wheel. It can be used to represent a delayed operation (such as downloading) in the application)
ProgressBar supports the following styles:
Widget. ProgressBar. Horizontal
Widget. ProgressBar. Small
Widget. ProgressBar. Large
Widget. ProgressBar. Inverse
Widget. ProgressBar. Small. Inverse
Widget. ProgressBar. Large. Inverse
If attr is used, the following attr can be used:
ProgressBarStyle
ProgressBarStyleHorizontal
ProgressBarStyleInverse
ProgressBarStyleLarge
ProgressBarStyleLargeInverse
ProgressBarStyleSmall
ProgressBarStyleSmallInverse
ProgressBarStyleSmallTitle
Inverse indicates that the progress bar is displayed in Reversed colors.
This example introduces the basic usage of ProgressBar. You can click the button to modify the progress value of the progress bar (two progress bars are used at the same time: the main progress bar and the secondary progress bar ).
Note that Activity also provides several methods related to the progress bar (displayed in the title bar) to control the progress bar display.
SetProgress (int progress)
SetProgressBarIndeterminate (boolean indeterminate)
SetProgressBarIndeterminateVisibility (boolean visible)
SetProgressBarVisibility (boolean visible)
For ProgressBar, the current value of the progress bar is modified through incrementProgressBy and incrementSecondaryProgressBy.
[Java]
Final ProgressBar progressHorizontal
= (ProgressBar) findViewById (R. id. progress_horizontal );
SetProgress (progressHorizontal. getProgress () * 100 );
SetSecondaryProgress (progressHorizontal. getSecondaryProgress ()
* 100 );
...
ProgressHorizontal. incrementProgressBy (-1 );
...
ProgressHorizontal. incrementSecondaryProgressBy (-1 );
Final ProgressBar progressHorizontal www.2cto.com
= (ProgressBar) findViewById (R. id. progress_horizontal );
SetProgress (progressHorizontal. getProgress () * 100 );
SetSecondaryProgress (progressHorizontal. getSecondaryProgress ()
* 100 );
...
ProgressHorizontal. incrementProgressBy (-1 );
...
ProgressHorizontal. incrementSecondaryProgressBy (-1 );