如何在Android中设置进度条的最大值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12616269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:13:14  来源:igfitidea点击:

How to set maximum value of progressbar in Android

androidonclickprogress-bar

提问by Jericho

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.

你好,我是 android 初学者,我正在创建简单的进度条程序。在我的程序中,我想设置进度条最大值 & 我想使用循环增加进度条进度,直到它没有完成我想在单击时执行此任务。

like:

喜欢:

progressbar.maximum = 100;

while(progressbar ! = 100)
{
    progressbar.value + 1;
}

回答by Pepelac

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

默认情况下,进度条在达到 100 时为满。
如有必要,您可以使用 android:max 属性调整最大值(满条的值)

android:max

android:max

Defines the maximum value the progress can take.

定义进度可以采用的最大值。

Must be an integer value, such as "100".

必须是整数值,例如“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.

这也可能是对包含此类型值的资源(以“@[package:]type:name”形式)或主题属性(以“?[package:][type:]name”形式)的引用.

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

or
probressbar.setMax(Value);

或者
probressbar.setMax(Value);

回答by Pratik

you can set progressbar by two way

您可以通过两种方式设置进度条

probressbar.setMax(maxValue);

or from in xml

或从 xml

<ProgressBar
     android:max="maxvalue"/>

回答by Gautam

You should be able to do the following:

您应该能够执行以下操作:

progressbar.setMax(maxValue);

Take a look at the API for ProgressBars here.

此处查看 ProgressBar 的 API 。