var*_*tty 5 android canvas drawtext
我正在开发一个图像评论应用程序.我在画布上画文字canvas.drawText(text, x, y, imgPaint);
这出现在一行中.当文本越过画布宽度时,我需要将该行拆分为多行
提前致谢
你需要使用StaticLayout:
TextPaint mTextPaint=new TextPaint();
StaticLayout mTextLayout = new StaticLayout("my text\nNext line is very long text that does not definitely fit in a single line on an android device. This will show you how!", mTextPaint, canvas.getWidth(), Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
canvas.save();
// calculate x and y position where your text will be placed
textX = 100;
textY = 100;
canvas.translate(textX, textY);
mTextLayout.draw(canvas);
canvas.restore();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3048 次 |
| 最近记录: |