标签:就是 paint ima class android中 images text 分享图片 length
float baseline = height/2 + mPaint.getTextSize()/2 - mPaint.getFontMetrics().descent;文字尺寸就是
protected void onDraw(Canvas canvas) { String testString = "测试:gafaeh:1234"; Paint mPaint = new Paint(); mPaint.setStrokeWidth(3); mPaint.setTextSize(40); mPaint.setColor(Color.RED); mPaint.setTextAlign(Align.LEFT); Rect bounds = new Rect(); mPaint.getTextBounds(testString, 0, testString.length(), bounds); FontMetricsInt fontMetrics = mPaint.getFontMetricsInt(); int baseline = (getMeasuredHeight() + mPaint.getTextSize) / 2 - fontMetrics.descent; canvas.drawText(testString,getMeasuredWidth() / 2 - bounds.width() / 2, baseline, mPaint); }
android中canvas.drawText参数的介绍以及绘制一个文本居中的案例
标签:就是 paint ima class android中 images text 分享图片 length
原文地址:http://www.cnblogs.com/ghhryr-lichl/p/7998285.html