我现在有一个文本,Hello我需要为这个说 12 或 18 应用字体大小,一旦我们将字体应用于文本,文本大小就会增加。
所以现在我需要使用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);
但它不起作用,请帮助
编辑
我正在尝试根据 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".