Is there an API method for calculating the size (i.e. width and height) of a string displayed on one line in a given font and font size?
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.
Paint mPaint = new Paint(); mPaint.setTextSize(/*put here ur size*/); mPaint.setTypeface(/* put here ur font type */); Rect bounds = new Rect(); mPaint.getTextBounds(text, 0, text.length(), bounds);
then make a call
bounds.width(); bounds.height();
The Paint class has a measureText () method that will give you the width in float
Paint p = new Paint(); int INFO_WINDOW_WIDTH = (int)p.measureText("this is string");
and another Paint.getTextBounds