I have seperated the background xml and the progress xml. but the background does not show up. I am trying to implement a custom circle progress bar. I want to show 2 progresses at the same time in the progress bar.
below code is the background xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id ="#android:id/background">
<shape
android:innerRadiusRatio="2.6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<gradient
android:centerColor="#333399"
android:endColor="#333399"
android:startColor="#333399"
android:type="sweep" />
</shape>
</item>
</layer-list>
below code is the progress layout
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/secondaryProgress">
<shape
android:innerRadiusRatio="2.6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<gradient
android:centerColor="#714338"
android:endColor="#714338"
android:startColor="#714338"
android:type="sweep" />
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
<gradient
android:centerColor="#FFFFFF"
android:endColor="#FFFFFF"
android:startColor="#FFFFFF"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
this is the progress bar code in activity.xml
<ProgressBar
android:id="#+id/sync_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="100dp"
android:layout_height="100dp"
android:indeterminate="false"
android:padding="1dp"
android:progressDrawable="#drawable/circular_progressbar"
android:background="#drawable/circular_progress_bg"/>
I am new in Kotlin and trying to make a progress bar that is a HALF CIRCLE in my app and shows how much someone has spend so far.
There are many solutions for round ones and normal ones, but I can't find one for a half circle.
IN MY activity_main.xml FILE:
...
<ProgressBar
android:id="#+id/circularProgressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="250dp"
android:layout_height="250dp"
android:max="100"
android:progress="50"
android:layout_centerInParent="true"
android:progressDrawable="#drawable/circular"
android:secondaryProgress="100"/>
<TextView
android:id="#+id/tv"
android:layout_width="250dp"
android:layout_height="250dp"
android:gravity="center"
android:text="25$"
android:layout_centerInParent="true"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
AND IN MY circular.xml FILE:
...
<item android:id="#android:id/secondaryProgress">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<gradient
android:centerColor="#DADADA"
android:endColor="#999999"
android:startColor="#FFFFFF"
android:type="sweep" />
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<gradient
android:centerColor="#03A9F4"
android:endColor="#0063B1"
android:startColor="#68CCFF"
android:type="sweep" />
</shape>
</rotate>
</item>
WHAT I WANT is a horizontally cut circle as a progress bar.
I don't know if I am even on the right track and also I don't know how to set the degrees and things in the circular.xml file to get what I want, I tried but every time I changed something the output made no sense.
I have a progress bar, it looks like in image 1 and it should look like image 2. Below is my code for the progress bar. Please advise how to do that. Attached images are links cause it won't allow me to upload images directly.
MyProgressBar
Requirement
Below is the code in Layout:
<ProgressBar
android:id="#+id/percentage_circle"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="161dp"
android:layout_height="161dp"
android:max="100"
android:progress="0"
android:progressDrawable="#drawable/xml_custom_circular_progress" />
Below is the code in drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/background" >
<shape
android:innerRadiusRatio="2.5"
android:thicknessRatio="25"
android:shape="ring"
android:useLevel="false">
<solid android:color="#color/black_50" />
<stroke android:color="#color/text_white"/>
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:thicknessRatio="25"
android:shape="ring"
>
<gradient
android:endColor="#color/history_graph_gradient_end"
android:angle="90"
android:startColor="#color/history_graph_gradient_start"
android:centerColor="#0033C2"
android:type="sweep" />
</shape>
</rotate>
</item>
<item android:id="#android:id/secondaryProgress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:thicknessRatio="25"
android:shape="ring"
>
<gradient
android:endColor="#color/history_graph_gradient_end"
android:angle="90"
android:startColor="#color/history_graph_gradient_start"
android:centerColor="#0033C2"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
I don't have inner borders showing up and the background of the progressbar. I really need help with it.
I download this code from internet (in the end I set the link)
for customize the color circular progress bar
But the circular progress bar is not rotating
Am I missing something?
the progress bar is "static"
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/secondaryProgress">
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:useLevel="true"
android:thicknessRatio="14.0">
<gradient
android:startColor="#color/colorBlanco"
android:endColor="#color/colorBlanco"
android:centerColor="#color/colorBlanco"
android:type="sweep" />
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:useLevel="true"
android:thicknessRatio="14.0">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%" />
<gradient
android:startColor="#color/colorAzul"
android:endColor="#color/colorAzul"
android:centerColor="#color/colorAzul"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
this code has my launcher
<ProgressBar
android:layout_gravity="center"
android:id="#+id/circularProgressbar"
android:layout_width="100dp"
android:layout_height="100dp"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false"
android:progress="80"
android:max="100"
android:secondaryProgress="100"
android:layout_below="#+id/img_logo_app_launcher"
android:progressDrawable="#drawable/custom_progressbar" />
Horizontal and Circular Progress Bar in Android
Set progressBar.setIndeterminateDrawable() to any drawable file it
will replace your moving loader to the defined moving image.
When I add horizontal ProgressBar it behaves as expected -- I set the progress value and it shows it.
However when I add ProgressBar (circular) it spins. And that's it. In such form it is more "please wait" indicator, that any progress bar, because progress value is not shown.
So my question is (assuming Progress in name means progress) -- how to stop spinning and shows progress value? For example if I set max to 100, and value to 50 I would expect to see half-circle arc.
In other words how to make circular ProgressBar to behave like horizontal ProgressBar, with only exception of the shape?
I know that this is an old post but I ran into the same issue and I make it work.
It is actually easier than you think, you have to set a custom progress in an xml file inside your drawable folder and handle the attributes "fromDegrees" and "toDegrees" from the < rotate > tag:
This is the code for custom_progress.xml (you can customize yours as you like but you must not modify "fromDegrees" and "toDegrees")
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:useLevel="false"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#0099ff"/>
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="-90"
android:toDegrees="-90">
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:angle="0"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#e0e0e0"/>
</shape>
</rotate>
</item>
</layer-list>
And for your progress bar you have to set this attributes:
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="100dp"
android:layout_height="100dp"
android:indeterminate="false"
android:max="100"
android:progress="20"
android:progressDrawable="#drawable/custom_progress" />
What is happening here is that the progress will start in degree -90 which for me is the top side of the progress bar view and towards the right and it will continue towards the same degree, this will make the view progress to start and end in the same degree.
NOTE:
If you set 0 for both "fromDegrees" and "toDegrees" the progress will start from the right side of the circle.
Hope it helps people with the same requirement.
Since Api 21 you can do something like that: Assuming that your ProgressBar defind this way:
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/progressBarStyleLarge"
android:id="#+id/progress_bar"
android:layout_width="#dimen/item_width"
android:layout_height="#dimen/item_height"
android:clickable="false"
android:indeterminate="true"
android:indeterminateDrawable="#drawable/progress"/>
and this is progress.xml:
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="76dip"
android:width="76dip" />
<gradient
android:angle="0"
android:endColor="#color/colorGrayText"
android:startColor="#android:color/transparent"
android:type="sweep"
android:useLevel="false" />
</shape>
Now you can do this on your ProgressBar:
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
if (progressBar != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
RotateDrawable rotateDrawable = (RotateDrawable) progressBar.getIndeterminateDrawable();
rotateDrawable.setToDegrees(0);
}
}
Like toadzky commented, there's no baked-in method. You might try this ProgressWheel. If nothing else, it should give you idea of how to implement it.
For determinate progress bar means the progress bar which doesn't keep on rotating and user can set a fixed percentage over that.
<ProgressBar
android:id="#+id/pb_sharpness"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="#dimen/dp_50"
android:layout_height="#dimen/dp_50"
android:layout_marginTop="#dimen/dp_16"
android:indeterminate="false"
android:max="100"
android:progressDrawable="#drawable/custom_progress_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
For adding drawable to above progress bar
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:useLevel="false"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#color/white_color"/>
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="180"
android:toDegrees="0"
>
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:angle="0"
android:type="sweep"
android:thicknessRatio="15.0">
<gradient
android:startColor="#color/color_5646F3"
android:endColor="#color/color_ED88FE" />
</shape>
</rotate>
</item>
You can access the visibility property of the progress bar and set it to invisible when you need it to be invisible like this
ProgressBar progressBar = view.findViewById<ProgressBar>(R.id.progressbar)
progressBar.visibility = ProgressBar.INVISIBLE