我通过添加到画布在 TextureView 中绘制文本。但文字并不流畅。线条和其他形状都很好。添加了抗锯齿。 例子
DrawThread(ISurfaceHolder surfaceHolder, Context context) {
this.surfaceHolder = surfaceHolder;
fontPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
fontPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 36, context.getResources().getDisplayMetrics()));
}
@Override
public void run() {
Canvas canvas;
while (running) {
canvas = null;
try {
canvas = surfaceHolder.lockCanvas();
synchronized (surfaceHolder) {
if (canvas == null)
continue;
drawPath(canvas);
}
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
private void drawPath(Canvas canvas) {
canvas.drawText(number, 500, 500, fontPaint);
}