I am trying to create a rounded progressbar. This is what I want to achieve
There is a grey color background ring. On top of it, a blue color progressbar appears which moves in a circular path from 0 to 360 in 60 or whatever amount of seconds.
Here is my example code.
<ProgressBar
android:id="@+id/ProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?android:attr/progressBarStyleLarge"
android:indeterminateDrawable="@drawable/progressBarBG"
android:progress="50"
/>
To do this, in the drawable "progressBarBG", I am creating a layerlist and inside that layer list I am giving two items as shown.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
android:shape="ring"
android:innerRadius="64dp"
android:thickness="8dp"
android:useLevel="false">
<solid android:color="@color/grey" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape
android:shape="ring"
android:innerRadius="64dp"
android:thickness="8dp"
android:useLevel="false">
<solid android:color="@color/blue" />
</shape>
</clip>
</item>
Now, the first grey ring is generated fine. The blue ring however starts from the left of the drawable and goes to the right just like how a linear progressbar works. This is how it shows at 50% progress with the red color arrow showing direction.
I want to move the blue progressbar in circular path as expected.
I have written detailed example on circular progress bar in android here on my blog demonuts.com. You can also fond full source code and explanation there.
Here's how I made circular progressbar with percentage inside circle in pure code without any library.
first create a drawable file called
circular.xml
Now in your
activity_main.xml
add following:In
activity_main.xml
I have used one circular image with white background to show white background around percentage. Here is the image:You can change color of this image to set custom color around percentage text.
Now finally add following code to
MainActivity.java
:If you want to make horizontal progressbar, follow this link, it has many valuable examples with source code:
http://www.skholingua.com/android-basic/user-interface/form-widgets/progressbar
try this method to create a bitmap and set it to image view.
I have done with easy way:
Please check screen shot for the same.
CustomProgressBarActivity.java:
activity_custom_progressbar.xml:
custom_progressbar_drawable.xml:
Hope this will help you.
I realized a Open Source library on GitHub CircularProgressBar that does exactly what you want the simplest way possible:
USAGE
To make a circular ProgressBar add CircularProgressBar in your layout XML and add CircularProgressBar library in your projector or you can also grab it via Gradle:
XML
You must use the following properties in your XML to change your CircularProgressBar.
Properties:
app:progress
(integer) >> default 0app:progressbar_color
(color) >> default BLACKapp:background_progressbar_color
(color) >> default GRAYapp:progressbar_width
(dimension) >> default 7dpapp:background_progressbar_width
(dimension) >> default 3dpJAVA
Fork or Download this library here >> https://github.com/lopspower/CircularProgressBar