canvas.drawText("hello world",0,0,new Paint());// 以上代码不显示任何文本信息注意 该方法的 两个参数, 第一个是 字符串 左边 的x 坐标(left), 第二个是 。。。 底部 的y 坐标(botton而不是top),
如果想让字符串按照自己的意愿显示正常, 需要
canvas.drawText("hello world", 0, GraphicsUtils.getFontHeight(null), new Paint());
其中 GraphicsUtils.getFontHeight(null) 是自定义的方法 代码附上
/** * 获取字体高度 * @param textSize : textSize==null时 获取字符串的默认字体, */ public static int getFontHeight(Integer textSize){ Paint paint = new Paint(); if(textSize != null){ paint.setTextSize(textSize); } FontMetrics fm = paint.getFontMetrics(); return (int)(fm.descent - fm.ascent); }