欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)計步進度的環(huán)形Progress

 更新時間:2017年02月17日 11:56:41   作者:周木水  
這篇文章主要為大家詳細介紹了Android實現(xiàn)計步進度的環(huán)形Progress,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

效果圖:

代碼實現(xiàn):

設(shè)置已完成步數(shù)和目標步數(shù):

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

設(shè)置進度:

  public void setProgress(int progress) {
    this.mProgress = progress;
    this.invalidate();
  }

設(shè)置畫筆屬性:

mPaint.setAntiAlias(true);
mPaint.setColor(Color.rgb(0xe9, 0xe9, 0xe9));
canvas.drawColor(Color.TRANSPARENT);
mPaint.setStrokeWidth(LINE_WIDTH_BG);
mPaint.setStyle(Paint.Style.STROKE);

繪制環(huán)形和背景:

canvas.drawArc(mRectF, -90, 360, false, mPaint);
mPaint.setColor(Color.rgb(0xf8, 0x60, 0x30));
canvas.drawArc(mRectF, -90, ((float) mProgress / mMaxProgress) * 360, false, mPaint);

繪制步數(shù)和單位:

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

繪制目標步數(shù):

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論