【发布时间】:2026-01-24 06:40:01
【问题描述】:
我正在使用视图并在位图上绘制一些文本,它没有固定大小,所以我希望文本适合我定义的矩形,如果需要将字符串拆分为几行。 我不知道如何在android中做到这一点。 我找到了一种使用 StaticLayout 的解决方案,但不起作用。 这是我的代码:
Bitmap arBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ar_bitmap);
canvas.drawBitmap(arBitmap ,bitmapPos,20, null);ll);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawText(textToDisplay,textPos , 35, paint);
谢谢
【问题讨论】: