繼承于ProgressBar實現,保留了Progressbar的特性,源碼在文尾。。
demo.gif
參數
name | format | description |
---|---|---|
borderWidth | integer | 圓弧邊框的寬度 |
progressStyle | tick/arc | 進度條類型,tick為帶刻度的 |
radius | integer | 半徑 |
arcbgColor | color | 圓弧的邊框背景 |
degree | integer | 弧度,設置為0即為圓形進度條,180為半圓 |
tickWidth | integer | 刻度的寬度 |
tickDensity | integer | 刻度的密度 2~8 越小越密 |
bgShow | boolean | 是否顯示圓弧邊框背景 |
arcCapRound | boolean | 圓弧的筆觸是否為圓形,tick無效 |
interface
提供了繪制圓弧中間區域的一個接口 ,可根據自己的需求自由繪制
/**
*
* @param canvas
* @param rectF 圓弧的Rect
* @param x 圓弧的中心x
* @param y 圓弧的中心y
* @param storkeWidth 圓弧的邊框寬度
* @param progress 當前進度
*/
public interface OnCenterDraw {
public void draw(Canvas canvas, RectF rectF, float x, float y,float storkeWidth,int progress);
}
默認提供了兩個實現
onImageCenter and OnTextCenter
Use
<com.czp.library.ArcProgress
android:id="@+id/myProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:degree="0"
app:progressStyle="arc" />
<com.czp.library.ArcProgress
android:id="@+id/myProgress01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/myProgress"
app:radius="80dp"
app:progressColor="@color/progressColor"
app:tickDensity="3" />
<com.czp.library.ArcProgress
android:id="@+id/myProgress02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/myProgress"
app:radius="90dp"
app:arcCapRound="true"
app:degree="180"
app:progressStyle="arc"
app:progressColor="@color/progressColorBlue"
app:tickDensity="3" />
mProgress.setOnCenterDraw(new ArcProgress.OnCenterDraw() {
@Override
public void draw(Canvas canvas, RectF rectF, float x, float y, float storkeWidth,int progress) {
Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setStrokeWidth(35);
textPaint.setColor(getResources().getColor(R.color.textColor));
String progressStr = String.valueOf(progress+"%");
float textX = x-(textPaint.measureText(progressStr)/2);
float textY = y-((textPaint.descent()+textPaint.ascent())/2);
canvas.drawText(progressStr,textX,textY,textPaint);
}
});
依賴
dependencies {
compile 'com.czp.arcProgressBar:ArcProgressBar:1.0.1'
}
寫完搜了一下。。。貌似重復造了個輪子。。。
后續補上幾個知識點~哇哈啊哈啊
源碼下載地址
喜歡的不妨來個Star呀~