我创建了自定义视图以在内部绘制自定义语音气泡,并且我想在自定义视图上放置一些文本。我使用drawTextOnPath但它不能正常工作,我希望文本逐行显示。
自定义视图 - 语音气泡
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setAntiAlias(true);
paint.setStrokeWidth(2);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setPathEffect(new CornerPathEffect(15) );
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setDither(true);
paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE,
Shader.TileMode.MIRROR));
Path path = new Path();
paint.setShadowLayer(4, 2, 2, 0x80000000);
path.moveTo(myPath[0].x, myPath[0].y);
for (int i = 1; i < myPath.length; i++){
path.lineTo(myPath[i].x, myPath[i].y);
}
path.close();
canvas.clipPath(path);
canvas.drawPath(path, paint);
canvas.save();
paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawTextOnPath(MessageBody, path, 10, 10, paint);
谢谢。