在我的应用程序中,我使用画布绘制文本。现在我想设置绘制文本的宽度。我只能设置x
,y
的位置。我无法设置宽度和高度。如何在android中的canvas方法中设置文本的宽度?
我的问题
更新 例如,“印度是我的祖国”,或者如果任何长度的文本不言而喻的画布之外,这是背景图像之外。 我想打印“印度是
我的祖国”如果我设置宽度呢?我想它转到下一行
@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); – Triode 2012-02-23 06:29:42
更新mt问题rajesh – Mercy 2012-02-23 06:50:16
希望这是你想引用我的答案兄弟,如果不是遗憾 – Triode 2012-02-23 08:08:57