问题
hello i am beginner in android & i am creating simple progressbar program. In my program i want to set progressbar maximum value & i want to increase progressbar progress using a loop till it's not get complete i want to perform this task on butten click.
like:
progressbar.maximum = 100;
while(progressbar ! = 100)
{
progressbar.value + 1;
}
回答1:
By default, the progress bar is full when it reaches 100.
If necessary, you can adjust the maximum value (the value for a full bar) using the android:max attribute
android:max
Defines the maximum value the progress can take.
Must be an integer value, such as "100".
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
<ProgressBar
android:id="@+id/progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:max="42" <--- it's the answer)
android:progress="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_header_relativelayout"
/>
orprobressbar.setMax(Value);
回答2:
you can set progressbar by two way
probressbar.setMax(maxValue);
or from in xml
<ProgressBar
android:max="maxvalue"/>
回答3:
You should be able to do the following:
progressbar.setMax(maxValue);
Take a look at the API for ProgressBars here.
来源:https://stackoverflow.com/questions/12616269/how-to-set-maximum-value-of-progressbar-in-android