国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現計步進度的環形Progress

2019-10-23 19:46:41
字體:
來源:轉載
供稿:網友

項目中需要實現一個計步進度的環形Progress,當未達到設定目標時,繪制特定弧度((已實現步數/目標步數)*360°)的圓弧。當已實現步數大于等于目標步數時繪制整個360°圓環。

效果圖:

Android計步進度Progress,Android環形進度Progress,Android計步環形進度

代碼實現:

設置已完成步數和目標步數:

  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);

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 铜川市| 吴忠市| 沂南县| 北海市| 那曲县| 屯昌县| 赤城县| 屯门区| 渭南市| 威海市| 台山市| 巴东县| 苏州市| 乳源| 西昌市| 甘肃省| 翁源县| 鹿邑县| 肥乡县| 鄱阳县| 酒泉市| 林口县| 荣昌县| 洛南县| 灌南县| 马鞍山市| 周口市| 霍山县| 舟山市| 来安县| 囊谦县| 鄢陵县| 承德县| 鄯善县| 五华县| 搜索| 靖宇县| 上栗县| 靖宇县| 板桥市| 隆昌县|