In the below example code I have created a Custom Circle Progress bar. Here first I have added Progress bar layout within activity_main.xml then I have created a new circular_progressbar.xml file in a drawable folder. In circular_progress bar.xml I have used rotate XML this rotate allows our form to rotate from 0 to 360 degrees. And I have also used shape.xml for creating a stylish progress bar, In shape.xml I have used these attributes- color, innerRadius, shape, useLevel and thickness.
For the ring you must set the following parameters:-
android:innerRadiusRatio – For using an inner radius of the ring
android:thicknessRatio – For using thickness of the ring
android:useLevel="true" – Indicates whether the progress bar level affects .
Step(1) activity_main.xml layout-
<ProgressBar
android:background="@color/center"
android:indeterminate="true"
android:layout_gravity="center"
style="?android:attr/progressBarStyleLarge"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/circular_progressbar" />
Step(2)-Created circular_progressbar.xml in drawable folder-
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<shape
android:innerRadiusRatio="4"
android:shape="ring"
android:useLevel="true"
android:thickness="2dp">
<solid android:color="@color/colorPrimaryDark"/>
</shape>
</rotate>
1 Comment(s)