When I call the function canvas.drawText()
in my custom view,I got strange result,like this:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.translate(50, 50);
mPaint.setTextSize(60);
String str = "helloworld";
float[] wids = new float[10];
mPaint.getTextWidths(str, wids);
float width = 0;
for (int j = 0; j < wids.length; j++) {
String string = String.valueOf(str.charAt(j));
canvas.drawText(string, width, 50, mPaint); //draw by characters
width = width + mPaint.measureText(string); //the start X
}
}
and this:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.translate(50, 50);
mPaint.setTextSize(60);
String str = "helloworld";
canvas.drawText(str, 0, 50, mPaint); // draw by strings
}
why the two methods run different? I need draw by characters,but its kerning is wrong! Anybody can guide me?