【发布时间】:2017-07-19 22:18:00
【问题描述】:
在我的应用程序中,我使用画布绘制文本。现在我想设置绘图文本的宽度。我只能设置 x , y 位置。我无法设置宽度和高度。
我的问题
更新 例如“印度是我的国家”,或者如果任何长度的文本超出背景图像之外的画布。 我想打印“印度是
我的国家“如果我设置宽度意味着我认为它会进入下一行
@Override
protected void onDraw(Canvas canvas1)
{
Paint paint = new Paint();
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ban_background);
Bitmap resizeImage1=Bitmap.createScaledBitmap(myBitmap,590,350,false);
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(20);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas1.drawText(CameraText, 100,175, paint);
}
}
【问题讨论】:
-
当你设置文本大小时,宽度和高度会自动设置,我认为你不能明确设置宽度和高度。但是如果你能解释一下你真正的问题是我可以帮助你。您可以像这样设置文本大小后获取文本的高度和宽度 Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds);
-
更新 mt 问题 rajesh
-
希望这是你想要的,如果不抱歉,请参考我的回答兄弟