自定義ProgressBar實現圓弧進度條
阿新 • • 發佈:2019-02-01
依賴
dependencies { compile 'com.czp.arcProgressBar:ArcProgressBar:1.0.1' }
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
提供了繪製圓弧中間區域的一個介面 ,可根據自己的需求自由繪製
123456789101112 | /** * * @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
123456789 | 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); } }); |
依賴
https://github.com/ZeeeeeeNo/ArcProgressBar(原始碼地址);