我正在尝试创建自定义视图,我在其中使用自定义字体绘制文本并想要控制笔触宽度。我已将onDraw
方法覆盖为如下所示:
protected void onDraw(Canvas canvas) {
Typeface mGothamFont =
Typeface.createFromAsset(getContext().getAssets(), "fonts/gotham_thin.ttf");
Paint mTextLargePaint = new TextPaint();
mTextLargePaint.setColor(Color.parseColor("#D0CFCF"));
mTextLargePaint.setStyle(Paint.Style.STROKE);
mTextLargePaint.setStrokeWidth(1.2f);
mTextLargePaint.setAntiAlias(true);
mTextLargePaint.setTextSize(65);
mTextLargePaint.setTypeface(mGothamFont);
canvas.drawText("Bla Bla", (getWidth() - mTextLargePaint.measureText("Bla Bla")) / 2.0f, 100, mTextLargePaint);
}
(忽略我在Paint
方法中创建onDraw
的事实,这仅用于示例)。
但无论我设置为setStrokeWidth的参数,文本都非常薄。我已尝试评论setTypeface
行,以便我使用常规系统字体,但仍然没有运气。
有什么建议吗?