Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set thickness of circular indeterminate progress bar android?

I have two nested circular indeterminate progress bars but I cannot set their thickness to an equal size. I have tried to customize it using shapes. However, that removes the default behaviour of the circular indeterminate progress. I customize like this and it made thickness equal but not getting default behaviour.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/progress">
        <rotate android:toDegrees="360">
            <shape
                android:shape="ring"
                android:thickness="4dp">
                <solid android:color="@color/white" />
            </shape>
        </rotate>
    </item>
</layer-list>

<ProgressBar
      android:id="@+id/download_progress4"
      android:layout_width="85dp"
      android:layout_height="85dp"
      android:layout_gravity="center"
      android:indeterminate="true"
      android:indeterminateDrawable="@style/ProgressThem" />

I want like this with default behaviour of circular indeterminate progress bar

but i want like this with default behaviour of circular indeterminate progress bar

like image 438
Mirza Ahmed Baig Avatar asked Feb 02 '18 11:02

Mirza Ahmed Baig


People also ask

How do I add a circular progress bar in Visual Studio?

In order to download NuGet Packages, right-click the project file, and choose "Manage NuGet Packages". Now, browse Circular Progress bar from the NuGet Packages. Download and install CircularProgressBar. In toolbox, under the general field, the installed Circular Progress bar is available.


3 Answers

There is actually an even easier way to do that with the material components:

<com.google.android.material.progressindicator.CircularProgressIndicator
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        app:trackThickness="3dp" />

More details in material docs -> https://material.io/components/progress-indicators/android#circular-progress-indicators

like image 53
rwozniak Avatar answered Oct 16 '22 22:10

rwozniak


Try this

USE

android:innerRadiusRatio="3"
android:thicknessRatio="20.0

SAMPLE CODE

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/progress">
        <rotate android:toDegrees="360">
            <shape
                android:shape="ring"
                android:thickness="4dp"
                android:innerRadiusRatio="3"
                android:thicknessRatio="20.0">
                <solid android:color="@color/white" />
            </shape>
        </rotate>
    </item>
</layer-list>
like image 31
AskNilesh Avatar answered Oct 16 '22 23:10

AskNilesh


If you want the modern animation rather than just rotation, you can copy and alter https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/drawable/progress_indeterminate_anim_medium_material.xml using it as the indeterminateDrawable.

<ProgressBar
    android:indeterminateDrawable="@drawable/new_progress_indeterminate_anim_medium_material"

To change the width in vector_drawable_progress_bar_medium.xml android:strokeWidth="1" for example.

It's a bit painful to do this as you also need to copy over the animation, interpolator and animator xml files to your project as they are private in the Android SDK.

like image 21
TTransmit Avatar answered Oct 16 '22 21:10

TTransmit