Last active
May 21, 2018 10:17
-
-
Save iamnaran/078004e2b4c818dcb981852617f0e9e6 to your computer and use it in GitHub Desktop.
Custom Circular Progress Bar Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ProgressBar | |
android:id="@+id/progress_bar" | |
style="?android:attr/progressBarStyleHorizontal" | |
android:layout_width="110dp" | |
android:layout_height="110dp" | |
android:background="@drawable/circle_shape" | |
android:indeterminate="false" | |
android:max="30" | |
android:progress="15" | |
android:progressDrawable="@drawable/circular_progress_bar" | |
android:layout_centerVertical="true" | |
android:layout_centerInParent="true" | |
android:layout_centerHorizontal="true" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<shape | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="ring" | |
android:innerRadiusRatio="2.5" | |
android:thickness="3dp" | |
android:useLevel="false"> | |
<solid android:color="#CCC" /> | |
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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.5" | |
android:shape="ring" | |
android:thickness="3dp" | |
android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 --> | |
<gradient | |
android:angle="0" | |
android:endColor="#42A530" | |
android:startColor="#42A530" | |
android:type="linear" | |
android:useLevel="false" /> | |
</shape> | |
</rotate> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ProgressBarAnimation progressBarAnimation; | |
progressBar = (ProgressBar) findViewById(R.id.progress_bar); | |
progressBarAnimation = new ProgressBarAnimation(vhHeaderTwo.progressBar, 0, Integer.parseInt(studentAttendance.getTotal().getPresentDays())); | |
progressBar.setMax(Integer.parseInt(studentAttendance.getTotal().getOperatingDays())); | |
progressBarAnimation.setDuration(800); | |
progressBarAnimation.setInterpolator(new AnticipateInterpolator()); | |
progressBar.startAnimation(progressBarAnimation); | |
progressBar.getProgressDrawable().setColorFilter(Color.parseColor(primaryColor), PorterDuff.Mode.SRC_IN); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProgressBarAnimation extends Animation { | |
private ProgressBar progressBar; | |
private float from; | |
private float to; | |
public ProgressBarAnimation(ProgressBar progressBar, float from, float to) { | |
super(); | |
this.progressBar = progressBar; | |
this.from = from; | |
this.to = to; | |
} | |
@Override | |
protected void applyTransformation(float interpolatedTime, Transformation t) { | |
super.applyTransformation(interpolatedTime, t); | |
float value = from + (to - from) * interpolatedTime; | |
progressBar.setProgress((int) value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment