Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a ProgressBar circular and in determinate mode? [duplicate]

I have to download some images and videos on the device and I like to track the progress by having a circular ProgressBar in determinate mode in overlay to them.

The problem is that, no matter what, the ProgressBar is still indeterminate.

Is there a way to have it circular and in determinate mode?

Layout

<ProgressBar
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:progressTint="@color/colorPrimary"
                android:indeterminate="false"
                android:max="100"
                android:layout_gravity="center"
                android:id="@+id/message_media_preview_progress"
                android:visibility="gone"
                />

Code

final ProgressBar progressBar = (ProgressBar) mView.findViewById(R.id.message_media_preview_progress);
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
storageController.downloadMedia(context, message.getVideoFile(),
        new ProgressListener<Integer>() {
            @Override
            public void onResult(Integer result) {
                progressBar.setProgress(result);
            }
        },
        new ResultListener<Boolean>() {
            @Override
            public void onResult(Boolean result) {
                if(result) {
                    progressBar.setVisibility(View.GONE);
                    setMediaClickListener(message);
                }else{
                    Toast.makeText(context,"Error downloading file",Toast.LENGTH_SHORT).show();
                }
            }
        });
like image 944
Jackie Degl'Innocenti Avatar asked Nov 16 '16 11:11

Jackie Degl'Innocenti


People also ask

How do you make a circular progress bar?

Step 1: First, we will design a basic progress bar structure using HTML. First, we will create a container div that holds both progress bars. After that, we will create another div inside the container div that creates the circular div element.

How do I stop indeterminate progress bar?

How do I stop indeterminate progress bar? An indeterminate progress bar animates constantly. You can stop the animation and clear the progress bar by making the progress bar determinate and setting the current value to the minimum.

What is indeterminate ProgressBar?

Indeterminate ProgressBars are a useful tool for communicating to our users that an operation is in progress when we cannot predict how long it is likely to take.

Which attribute is used to display ProgressBar horizontally?

In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.


2 Answers

Unfortunately, this is not possible with stock Android ProgressBar. Look for external libraries like:

http://github.com/dinuscxj/CircleProgressBar

like image 91
R. Zagórski Avatar answered Oct 23 '22 15:10

R. Zagórski


Now it is possible to have determinate circular progress bar in newer versions of material design library:

<com.google.android.material.progressindicator.CircularProgressIndicator
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Refer here for more information.

like image 45
Mahozad Avatar answered Oct 23 '22 15:10

Mahozad