Canvas as the drawing text, uses the FontMetrics object to calculate the coordinates of the position. public static class FontMetrics {public float top; public float ascent; public float descent; public float bottom; public float leading; Its various baselines can be consulted:
is actually drawn through the code, the specific code is as follows: mpaint.reset (); mpaint.setcolor (Color.White); mpaint.settextsize (80); //FontMetrics object fontmetrics fontmetrics = Mpaint.getfontmetrics (); String Text = "ABCDEFG"; //calculates each coordinate float textWidth = mpaint.measuretext (text); float BaseX = 30; float Basey = 700; float topy = Basey + fontmetrics.top; float Ascenty = Basey + fontmetrics.ascent; float Descenty = Basey + fontmetrics.descent; float bottomy = Basey + fontmetrics.bottom; //Draw Text canvas.drawtext (text, BaseX, Basey, Mpaint); //Baseline Painted mpaint.setcolor (color.red); canvas.drawline (BaseX, Basey, BaseX + textWidth, Basey, Mpaint); mpaint.settextsize (20); canvas.drawtext ("base", BaseX + textWidth, Basey, Mpaint); //BasE painted canvas.drawcircle (BaseX, Basey, 5, mpaint); //Topline painted mpaint.setcolor (Color.ltgray); canvas.drawline (BaseX, topy, BaseX + textWidth, topy, Mpaint); canvas.drawtext ("Top", BaseX + textWidth, topy, Mpaint); //Ascentline painted mpaint.setcolor (Color.green); canvas.drawline (BaseX, Ascenty, BaseX + textWidth, Ascenty, Mpaint); canvas.drawtext ("Ascent", BaseX + textWidth, Ascenty + ten, mpaint); //Descentline painted mpaint.setcolor (Color.yellow); canvas.drawline (BaseX, Descenty, BaseX + textWidth, Descenty, Mpaint); canvas.drawtext ("Descent", BaseX + textWidth, Descenty, Mpaint); //Buttomline painted mpaint.setcolor (Color.magenta); canvas.drawline (BaseX, bottomy, BaseX + textWidth, bottomy, Mpaint); canvas.drawtext ("Buttom", BaseX + textWidth, bottomy + ten, mpaint); &nBSP, I believe that through the above procedures, can be a good understanding of topline,buttomline,baseline,ascentline,descentline. In addition: The Paint class has two methods public native float ascent (); public native float descent (); ascent (): The distance above the baseline (height above baseline) descent (): The distance below the Baseline (height below baseline) so ascent () + descent () can be regarded as the height of the text. So far, how to get the height and width of the text has been announced:
The output of fonts in Android view DrawText