我正在使用自定义字体并在 android 中使用 Paint 对象向 Canvas 添加文本,例如:
Paint paint = new Paint();
paint.setARGB(255, 255, 255, 255);
paint.setTextSize(29);
paint.setAntiAlias(true);
paint.setTypeface(font);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern
final TextPaint tp = new TextPaint(paint);
final TextPaint tpStroke = new TextPaint(strokePaint);
// canvas.translate(15, 5);
canvas.translate(20, 5);
StaticLayout sl = new StaticLayout(textOne.getText().toString(), tp, (finalBitmapOne.getWidth()-10), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
sl.draw(canvas);
我对前导/行高不满意,我该如何调整?
我可以通过以下方式获得领先地位:
FontMetrics fmPaint = paint.getFontMetrics();
fmPaint.leading;
但是我该如何调整呢?
最佳答案
来自 getFontMetrics
的文档(强调我的):
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc. If metrics is not null, return the fontmetric values in it.
您不设置它来更改间距,您阅读它以确定推荐的间距应该是多少。您必须自己手动重新定位坐标,即在绘制每条线之间再次平移 Canvas 。
关于android - 在android中设置paint/fontmetrics的领先,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14147883/