相关疑难解决方法(0)

获取包含字体大小的文本高度并设置该高度

我有一个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".

android paint android-webview

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-webview ×1

paint ×1