我有一个Hello现在称为文本的文本我需要在文本大小增加的文本中应用字体后立即对此说12或18应用fontsize.
所以现在我需要使用paint获取文本高度,包括字体大小.
我尝试过以下涂料:
String finalVal ="Hello";
Paint paint = new Paint();
paint.setTextSize(18);
paint.setTypeface(Typeface.SANS_SERIF);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.FILL);
Rect result = new Rect();
// Measure the text rectangle to get the height
paint.getTextBounds(finalVal, 0, finalVal.length(), result);
Run Code Online (Sandbox Code Playgroud)
但它不起作用,请帮忙
编辑
我试图根据textheight动态设置webview的高度我得到单行的文本高度,"Hello"但如果文本中有两行"My name is abc and my dads name is xyz and my moms name is 123" now its not getting the proper text height".