java.lang.Object | |||
android.view.View | Drawable.Callback KeyEvent.Callback | ||
android.widget.ProgressBar |
Visual indicator of progress in some operation. Displays a bar to the user representing how far the operation has progressed; the application can change the amount of progress (modifying the length of the bar) as it moves forward. There is also a secondary progress displayable on a progress bar which is useful for displaying intermediate progress, such as the buffer level during a streaming playback progress bar.
A progress bar can also be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation. This mode is used by applications when the length of the task is unknown.
The following code example shows how a progress bar can be used from a worker thread to update the user interface to notify the user of progress:
public class MyActivity extends Activity { private static final int PROGRESS = 0x1; private ProgressBar mProgress; private int mProgressStatus = 0; private Handler mHandler = new Handler(); protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.progressbar_activity); mProgress = (ProgressBar) findViewById(R.id.progress_bar); // Start lengthy operation in a background thread new Thread(new Runnable() { public void run() { while (mProgressStatus < 100) { mProgressStatus = doWork(); // Update the progress bar mHandler.post(new Runnable() { public void run() { mProgress.setProgress(mProgressStatus); } }); } } }).start(); } }
XML attributes
See ProgressBar Attributes, View Attributes
Styles
Attribute name | Related methods | |
---|---|---|
android:progressBarStyle | Default ProgressBar style. | |
android:progressBarStyleHorizontal | Horizontal ProgressBar style. | |
android:progressBarStyleLarge | Large ProgressBar style. | |
android:progressBarStyleSmall | Small ProgressBar style. |
ProgressBar(Context context) | ||||||
Create a new progress bar with range 0...100 and initial progress of 0. | ||||||
ProgressBar(Context context, AttributeSet attrs) | ||||||
ProgressBar(Context context, AttributeSet attrs, int defStyle) |
Drawable | getIndeterminateDrawable() | |||||
Get the drawable used to draw the progress bar in indeterminate mode. |
||||||
Interpolator | getInterpolator() | |||||
Gets the acceleration curve type for the indeterminate animation. | ||||||
synchronized | int | getMax() | ||||
Return the upper limit of this progress bar's range. |
||||||
synchronized | int | getProgress() | ||||
Get the progress bar's current level of progress. |
||||||
Drawable | getProgressDrawable() | |||||
Get the drawable used to draw the progress bar in progress mode. |
||||||
synchronized | int | getSecondaryProgress() | ||||
Get the progress bar's current level of secondary progress. |
||||||
synchronized | final | void | incrementProgressBy(int diff) | |||
Increase the progress bar's progress by the specified amount. |
||||||
synchronized | final | void | incrementSecondaryProgressBy(int diff) | |||
Increase the progress bar's secondary progress by the specified amount. |
||||||
void | invalidateDrawable(Drawable dr) | |||||
Invalidates the specified Drawable. | ||||||
synchronized | boolean | isIndeterminate() | ||||
Indicate whether this progress bar is in indeterminate mode. |
||||||
void | postInvalidate() | |||||
Cause an invalidate to happen on a subsequent cycle through the event loop. | ||||||
synchronized | void | setIndeterminate(boolean indeterminate) | ||||
Change the indeterminate mode for this progress bar. |
||||||
void | setIndeterminateDrawable(Drawable d) | |||||
Define the drawable used to draw the progress bar in indeterminate mode. |
||||||
void | setInterpolator(Interpolator interpolator) | |||||
Sets the acceleration curve for the indeterminate animation. | ||||||
void | setInterpolator(Context context, int resID) | |||||
Sets the acceleration curve for the indeterminate animation. | ||||||
synchronized | void | setMax(int max) | ||||
Set the range of the progress bar to 0... |
||||||
synchronized | void | setProgress(int progress) | ||||
Set the current progress to the specified value. |
||||||
void | setProgressDrawable(Drawable d) | |||||
Define the drawable used to draw the progress bar in progress mode. |
||||||
synchronized | void | setSecondaryProgress(int secondaryProgress) | ||||
Set the current secondary progress to the specified value. |
||||||
void | setVisibility(int v) | |||||
Set the enabled state of this view. |
synchronized | void | onDraw(Canvas canvas) | ||||
Implement this to do your drawing. | ||||||
synchronized | void | onMeasure(int widthMeasureSpec, int heightMeasureSpec) | ||||
Measure the view and its content to determine the measured width and the measured height. |
||||||
void | onSizeChanged(int w, int h, int oldw, int oldh) | |||||
This is called during layout when the size of this view has changed. | ||||||
boolean | verifyDrawable(Drawable who) | |||||
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. |
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symbol progressBarStyle.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symbol progressBarStyleHorizontal.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symbol progressBarStyleLarge.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute resource symbol progressBarStyleSmall.
context | the application environment |
---|
Get the drawable used to draw the progress bar in indeterminate mode.
Return the upper limit of this progress bar's range.
Get the progress bar's current level of progress. Return 0 when the progress bar is in indeterminate mode.
Get the drawable used to draw the progress bar in progress mode.
Get the progress bar's current level of secondary progress. Return 0 when the progress bar is in indeterminate mode.
Increase the progress bar's progress by the specified amount.
diff | the amount by which the progress must be increased |
---|
Increase the progress bar's secondary progress by the specified amount.
diff | the amount by which the secondary progress must be increased |
---|
dr | the drawable to invalidate |
---|
Indicate whether this progress bar is in indeterminate mode.
Change the indeterminate mode for this progress bar. In indeterminate mode, the progress is ignored and the progress bar shows an infinite animation instead.
If this progress bar's style only supports indeterminate mode (such as the circular progress bars), then this will be ignored.indeterminate | true to enable the indeterminate mode |
---|
Define the drawable used to draw the progress bar in indeterminate mode.
d | the new drawable |
---|
interpolator | The interpolator which defines the acceleration curve |
---|
context | The application environment |
---|---|
resID | The resource identifier of the interpolator to load |
Set the range of the progress bar to 0...max.
max | the upper range of this progress bar |
---|
Set the current progress to the specified value. Does not do anything if the progress bar is in indeterminate mode.
progress | the new progress, between 0 and getMax() |
---|
Define the drawable used to draw the progress bar in progress mode.
d | the new drawable |
---|
Set the current secondary progress to the specified value. Does not do anything if the progress bar is in indeterminate mode.
secondaryProgress | the new secondary progress, between 0 and getMax() |
---|
canvas | the canvas on which the background will be drawn |
---|
Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.
CONTRACT: When overriding this method, you
must call setMeasuredDimension(int, int) to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int). Calling the superclass'
onMeasure(int, int) is a valid use.
The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.
If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).
widthMeasureSpec | horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec. |
---|---|
heightMeasureSpec | vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec. |
w | Current width of this view. |
---|---|
h | Current height of this view. |
oldw | Old width of this view. |
oldh | Old height of this view. |
Be sure to call through to the super class when overriding this function.
who | The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class. |
---|
Copyright 2007 Google Inc. | Build 0.9_r1-98467 - 14 Aug 2008 18:48 |