github:https://github.com/HarryXR/android

  • 水平进度条
    测量
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {     int textHeight = ViewUtils.getTextHeight(mAlertTextPaint);    int height = 0;  if (!TextUtils.isEmpty(mLeftAlert) ||                   !TextUtils.isEmpty(mRightAlert))  {        height += textHeight;  //加上文字高度  }  height += LINE_MARGIN;    height += STROKE_WIDTH * 2;    height += LINE_MARGIN; if (!TextUtils.isEmpty(mLeftContent) || !TextUtils.isEmpty(mRightContent)) {        height += textHeight;    }    setMeasuredDimension(widthMeasureSpec, height);}

ViewUtils测量文本高度

public static int getTextHeight(Paint paint) {    Paint.FontMetrics fontMetrics = paint.getFontMetrics();   return (int) Math.ceil(fontMetrics.descent - fontMetrics.ascent);}

画进度

private void drawProgress(Canvas canvas) {    //画灰色进度    Paint bgPaint = getProgressPaint();     bgPaint.setColor(mProgressBg);    //左右扣除半个圆距离    canvas.drawLine(STROKE_WIDTH / 2, mHeight / 2, mWidth -       STROKE_WIDTH / 2, mHeight / 2, bgPaint);    //画绿色进度     Paint progressPaint = getProgressPaint();        progressPaint.setColor(mProgressColor);   int stopX = (int) ((mWidth - STROKE_WIDTH) * mProgress);    canvas.drawLine(STROKE_WIDTH / 2, mHeight / 2, stopX, mHeight / 2, progressPaint);    //画指示      Paint textPaint = getIndicatorPaint();    int textWidth = ViewUtils.getTextWidth(textPaint, mAlert);   Paint indicatorPaint = getProgressPaint();    indicatorPaint.setColor(mIndicatorBg);    indicatorPaint.setStrokeWidth(ALERT_STROKE_WIDTH);    canvas.drawLine(stopX - textWidth / 2, mHeight / 2, stopX + textWidth / 2, mHeight / 2, indicatorPaint);    //画指示文字    Paint.FontMetrics fm = textPaint.getFontMetrics();  int alertY = mHeight / 2 + (int) (Math.abs(fm.bottom + fm.top)) / 2;     canvas.drawText(mAlert, stopX - textWidth / 2, alertY, textPaint);}
  • 圆环
    大家看源码吧,涉及到一些数学公式的计算,原理类似

更多相关文章

  1. Android(安卓)珍藏(三)
  2. 控件——SeekBar
  3. 【Android开发学习27】界面控件之进度条(ProgressBar)
  4. Android(安卓)Actionbar自定义标题栏
  5. EditText高度的改变
  6. 使用ProgressBar实现加载进度条
  7. 关于progressbar进度条的显示风格及一些属性的应用
  8. 安卓开发---进度条
  9. 【Android(安卓)view】获取状态栏高度statu bar height的正确姿

随机推荐

  1. centos6.8 update centos7.2
  2. centos6 无法使用yum命令
  3. xxl-job 搭建使用随笔
  4. 浅析liunx负载均衡(apache篇)
  5. flex容器属性的功能,参数,以及作用
  6. mysql数据库CURD中常用操作
  7. 0324作业
  8. shell变量的类型
  9. 2021上半年软考报名流程详解!赶紧了解一下
  10. 驱动下一代技术浪潮,我们更专注价值落地