Is there an API method for calculating the size (i.e. width and height) of a string displayed on one line and in a given font and font size?
As code, the scaling looks like this: Here the text is normal, <SPAN STYLE="font-size:18.0pt">here the text changes to 18.0pt,</SPAN> and here it returns to normal. Here the text is normal, <SPAN STYLE="font-size:18px">here the text changes to 18px,</SPAN> and here it returns to normal.
To use preset sizes to set up the autosizing of TextView in XML, use the android namespace and set the following attributes: Set the autoSizeText attribute to either none or uniform. none is a default value and uniform lets TextView scale uniformly on horizontal and vertical axes.
Paint p = new Paint();
p.setTypeface(TypeFace obj); // if custom font use `TypeFace.createFromFile`
p.setTextSize(float size);
float textWidth = p.measureText("Your string");
// you get the width here and textsize is the height.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With