android drawText()使用小记

来源:互联网 发布:数据库锁的原理 编辑:程序博客网 时间:2024/04/29 09:16

1.对于drawText()的使用网上有很多说明,多次使用后总结如下:           //确定文字绘制区域 Rect targetRect = new Rect(0, (int) ((2*r)-ImageTop-ModeTextSize), getWidth(), (int)((2*r)-ImageTop));                   mPaint.setColor(Color.RED);//需要在<span style="font-family: Arial, Helvetica, sans-serif;">mPaint.getFontMetricsInt();之前设置设置字体大小或者默认大小            mPaint.setTextSize(ModeTextSize);            mPaint.setColor(Color.WHITE);            Paint.FontMetricsInt fontMetrics = mPaint.getFontMetricsInt();//部分网上资料这里使用的是fontMetrics.bottom,发现总是偏下,但使用bottom好像是合理的,不知道具体是什么原因,猜想可能谷歌给的上部分空白空间给特殊语种的,或者拼音标注什么的,待查            int baseline = (targetRect.bottom + targetRect.top - fontMetrics.ascent + fontMetrics.descent) / 2- fontMetrics.bottom;            mPaint.setTextAlign(Paint.Align.CENTER);            canvas.drawText(TxMode, targetRect.centerX(), baseline, mPaint);


      

0 0
原创粉丝点击