如何适应android画布中的文本宽度?
您好,我的应用程序是在画布中绘制文本,其工作正常。我的问题是,当我的文本很大时,它超出了画布。
例如 text="how are you" 它正确地适合画布。但是而 text="hi hello how are you" 就像很长的文本。它超出了画布。任何人都可以帮助我。提前致谢!
canvas1.drawColor(Color.BLACK);
canvas1.drawBitmap(resizeImage1,10,5, null);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setTextSize(25);
paint.setColor(Color.BLUE);
paint.setFakeBoldText(true);
paint.setTextSize(30);
canvas1.drawText(mytext, 10,175, paint);
hi my application is draw the text in canvas its working fine.my problem while my text is large is goes outside of the canvas.
for example text="how are you" its correctly fit into the canvas.but while text="hi hello how are you"
like lenghthy text.it goes outside form the canvas.anybody kindly help me.Thanks in advance!
canvas1.drawColor(Color.BLACK);
canvas1.drawBitmap(resizeImage1,10,5, null);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setTextSize(25);
paint.setColor(Color.BLUE);
paint.setFakeBoldText(true);
paint.setTextSize(30);
canvas1.drawText(mytext, 10,175, paint);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用静态布局,即使您通过自动对齐文本增加了一些限制,它也会自动对齐文本。
Use Static layouts, it will take care of auto aligning your text even if you increase it by some limit, by auto aligning the text.
canvas1.drawBitmap(resizeImage1,IMAGE_WIDTH,5,空);
canvas1.drawBitmap(resizeImage1,IMAGE_WIDTH ,5, null);
很可能您超出了位图的宽度。
每个画布都有一个与其关联的位图,位图的宽度可能小于文本的宽度。
因此,当您尝试绘制文本时,它会超出位图的边界,因此您无法看到文本的其余部分。
尝试增加位图的大小。
Very lickely that you are exceeding the width of the bitmap.
Each canvas has a bitmap associated with it, the width of the bitmap might be smaller than the width of the text.
So when you try to draw the text it is going beyond the boundary of the bitmap and hence you are not able to see the rest of the text.
Try increasing the size of the bitmap.