【发布时间】:2012-12-25 23:16:44
【问题描述】:
我有一个名为 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".
【问题讨论】:
-
究竟是什么不起作用?
-
嗯...听起来很奇怪。为什么需要这样做?
-
@Goofy 我发布了解决方案,它对我有用。
标签: android android-webview paint