【发布时间】:2014-08-14 23:19:19
【问题描述】:
我正在尝试获取文本字符串的宽度(以像素为单位),我得到的值为 8,这不会产生影响,因为这意味着每个字母的宽度为 1 个像素。 我有以下代码
Rect bounds = new Rect();
Paint paint = new Paint();
paint.setTextSize(12);
paint.getTextBounds("ABCDEFGHI", 0, 1, bounds);
width=bounds.right; // this value is 8
bounds 的值为 0,0,8,9
【问题讨论】:
-
如果您只需要宽度,请尝试paint.measureText。这就是我所做的,因为我发现 getTextBounds 有一些不准确之处。
标签: android