Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(Color.WHITE);
textPaint.setTextSize(60);
textPaint.setStyle(Paint.Style.FILL);
//该方法即为设置基线上那个点究竟是left,center,还是right 这里我设置为center
textPaint.setTextAlign(Paint.Align.CENTER);
float bottom = fontMetrics.bottom;//为基线到字体下边框的距离,即上图中的bottom
int baseLineY = (int) (height/2 - top/2 - bottom/2);//基线中间点的y轴计算公式
//文字的高度为bottom-top值 top为负值baseline以上为负值baseline以下为正值
canvas.drawText(progress+"%",width/2,baseLineY,textPaint);
textPaint.setColor(Color.WHITE);
textPaint.setTextSize(60);
textPaint.setStyle(Paint.Style.FILL);
//该方法即为设置基线上那个点究竟是left,center,还是right 这里我设置为center
textPaint.setTextAlign(Paint.Align.CENTER);
Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
float bottom = fontMetrics.bottom;//为基线到字体下边框的距离,即上图中的bottom
int baseLineY = (int) (height/2 - top/2 - bottom/2);//基线中间点的y轴计算公式
//文字的高度为bottom-top值 top为负值baseline以上为负值baseline以下为正值
canvas.drawText(progress+"%",width/2,baseLineY,textPaint);