您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關Android項目中使用Progress實現一個環形進度條,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
效果圖:
代碼實現:
設置已完成步數和目標步數:
public void setStep(int stepDone, int stepGoal) { this.stepDone = stepDone; this.stepGoal = stepGoal; int progess = (stepDone * 100) / stepGoal; if (progess > 100) { setProgress(100); } else { setProgress(progess); } }
設置進度:
public void setProgress(int progress) { this.mProgress = progress; this.invalidate(); }
設置畫筆屬性:
mPaint.setAntiAlias(true); mPaint.setColor(Color.rgb(0xe9, 0xe9, 0xe9)); canvas.drawColor(Color.TRANSPARENT); mPaint.setStrokeWidth(LINE_WIDTH_BG); mPaint.setStyle(Paint.Style.STROKE);
繪制環形和背景:
canvas.drawArc(mRectF, -90, 360, false, mPaint); mPaint.setColor(Color.rgb(0xf8, 0x60, 0x30)); canvas.drawArc(mRectF, -90, ((float) mProgress / mMaxProgress) * 360, false, mPaint);
繪制步數和單位:
mPaint.setStrokeWidth(TEXT_WIDTH); String text = stepDone + context.getString(R.string.step_unit); int textHeight = height / 4; mPaint.setTextSize(textHeight); int textWidth = (int) mPaint.measureText(text, 0, text.length()); mPaint.setStyle(Paint.Style.FILL); canvas.drawText(text, width / 2 - textWidth / 2, height / 2 + textHeight / 4, mPaint);
繪制目標步數:
String textGoal = "/" + stepGoal; int textGoalHeight = height / 8; mPaint.setTextSize(textGoalHeight); int textGoalWidth = (int) mPaint.measureText(textGoal, 0, textGoal.length()); mPaint.setStyle(Paint.Style.FILL); canvas.drawText(textGoal, width / 2 - textGoalWidth / 2, height / 2 + textHeight / 2 + textGoalHeight, mPaint);
上述就是小編為大家分享的Android項目中使用Progress實現一個環形進度條了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。