I have defined a circular progress bar using the following drawable "ciruclar_progress_bar.xml"
<?xml version="1.0" encoding="utf-8"?>
<item android:id="@android:id/progress">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="@color/gray"
android:endColor="@color/gray"
android:startColor="@color/gray"
android:type="sweep" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="@color/green"
android:endColor="@color/green"
android:startColor="@color/green"
android:type="sweep" />
</shape>
</item>
and I have used this drawable for ProgressBar
in my layout using the following code
<ProgressBar
android:id="@+id/progressWheel"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="152dp"
android:layout_height="152dp"
android:layout_centerInParent="true"
android:progress="100"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar" />
I used following code to show progress on the ProgressBar
progressWheel.setSecondaryProgress(percent);
(Used secondary progress because the green color should come on top of the black color of the ring.)
This draws the circular ProgressBar
whose starting position is on the right (0°) as shown in the following image
I want the progress to start from the top as shown in the following image
I tried putting android:angle="270"
in the gradient tag of drawable xml but had no luck. Is there any way I can start the sweep angle from the top?
Here's how I made circular progressbar with percentage inside circle in pure code without any library.
Reference is taken from here : circular progress bar android
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
Thanks to @Zeba I got my answer. For people having the same problem here is the updated
circular_progress_bar.xml
A more simple solution I found is rotating the view 270 degrees, setting the inner text to transparent and setting new TextView on top of the circular progress bar with your data-
You can also apply a rotation to your ProgressBar in layout XML. In your case -90° would solve your problem.
Try specifying rotation degrees to your progress items.
A simple solution for rotating any view by some angle is giving rotation in XML.