Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set maximum value of progressbar in Android [closed]

I want to set the maximum value of a ProgressBar in Android.

I know I can set the current progress with setProgress or android:progress, but how do I set the maximum value?

like image 381
Jericho Avatar asked Sep 27 '12 07:09

Jericho


People also ask

What is used to set the maximum value of the progress bar?

The maximum value of progress bar can be set by using max property value. Property Values: level: It returns the list of progress bar. max: It is used to set or return the progress bar value of max attribute.

How do I show percentage progress on Android?

setMax(int max_value)– It sets the maximum value of the progress in the progress bar. setProgress(int prog_val)– It updates the progress to the progress value that is passed in it. show(Context context, CharSequence title, CharSequence msg)– It displays the progress bar.

What is a difference between SeekBar and ProgressBar in Android?

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.


1 Answers

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

or
probressbar.setMax(Value);

like image 114
Laser Avatar answered Nov 15 '22 06:11

Laser