android - 在Android上计算字符串的宽度

标签 android text-rendering

我需要知道给定字体句柄(或字体名称 + 字体大小 + 字体样式数据)的文本字符串的宽度。

在 Windows 中我曾经使用 GetTextExtentPoint()

最佳答案

使用此代码

 Rect bounds = new Rect(); 
 Paint textPaint = textView.getPaint();
 textPaint.getTextBounds(text, 0, text.length(), bounds); 
 int height = bounds.height(); 
 int width = bounds.width();

关于android - 在Android上计算字符串的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15355950/

相关文章:

Android 应用程序在方向更改期间丢失数据

android - react native : Using a panResponder inside of a scrollview broken on android

css - Safari 使用带有 optimizeLegibility 的 Typekit 移除字间距

html - 有没有办法旋转文本输入?

android - 在 Android 中支持使用 OpenType 字体的复杂文本布局

css - Chrome 渲染白色文本过于大胆

java - 如何使用 URL 从数据库中打印表中的多条记录

android - 将数组从 .js 文件传递​​到 .html 文件

android - 如果有 Canvas.rotate(90),Canvas.drawPoint() 不起作用?

css - 字体大小会影响连字的呈现吗?