Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ProgressBar of style large Thinner in width android?

I have the mic icon and surrounding the mic icon, I need to place the Progress Bar to handle some running process like below:

<ImageView
            android:id="@+id/iv_mic_movable"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="68dp"
            android:src="@drawable/record" />

        <ProgressBar
            android:id="@+id/pb_assist"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="53dp"
            android:visibility="gone" />

The above code shows the UI as follows:

enter image description here

I want to show the progress bar like this, But this progress is very Thick. How to make it somewhat thinner with only 1dp?

like image 477
Siraj Sumra Avatar asked Dec 08 '22 19:12

Siraj Sumra


2 Answers

None of the above answers worked for me. Struggling around found a below working solution.

progressbar_circular.xml. Use android:thicknessRatio for thickness of the circle. More the value will be, thinner it will be.

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="0"
    android:toDegrees="360" >

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="40"
        android:useLevel="false" >

        <size
            android:height="48dip"
            android:width="48dip" />

        <gradient
            android:centerColor="@color/colorPrimary"
            android:centerY="0.50"
            android:endColor="@color/color_black"
            android:startColor="@color/colorPrimary"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

Progress bar layout will be like below:

<ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        style="?android:attr/progressBarStyleLarge"
        android:indeterminateDrawable="@drawable/progressbar_circular"
        android:layout_gravity="center_horizontal"
        android:visibility="visible"/>
like image 92
Namrata Bagerwal Avatar answered Dec 10 '22 12:12

Namrata Bagerwal


Here is custom ProgressBar. You can set thickness of progress inside shape.

<ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="172dp"
        android:layout_height="172dp"
        android:indeterminate="false"
        android:max="100"
        android:visibility="visible"
        android:progress="0"
        android:layout_gravity="center_horizontal" //updated line
        android:layout_marginTop="53dp"            //updated line
        android:background="@drawable/circle_shape"
        android:progressDrawable="@drawable/circle_progress_foreground"
        />

circle_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="2.2"
android:thickness="5dp"
android:useLevel="false">

<solid android:color="#ABBAC2" />

</shape>

circle_progress_foreground.xml

Change android:thickness as per your requirement

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="270"
    android:toDegrees="270">

    <shape
        android:innerRadiusRatio="2.7"
        android:shape="ring"
        android:thickness="2dp"
        android:useLevel="true">

        <solid android:color="#fbcb09" />

    </shape>

</rotate>
like image 28
Kishore Jethava Avatar answered Dec 10 '22 12:12

Kishore Jethava