如何计算像素串字体宽度? [英] How to calculate string font width in pixels?

查看:448
本文介绍了如何计算像素串字体宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要计算在机器人像素字符串字体宽度。我有字符串数组,我追加所有这些数组元素形成一个字符串。所以我要在两个连续的阵列之间element.i我把这个最后的字符串到TextView中设置固定的间距。最后,我加入这个TextView的为tablerow。总之我想与标题和值查看表结构。我看过很多帖子在这里,但没有得到解决方案这一点。

I want to calculate string font width in pixels in android. I am having string array and I am appending all these array elements to form one string. so I have to set fixed spacing in between two consecutive array element.i am placing this final string into textview. Finally I am adding this textview to tablerow. In short i want to view table structure with title and values. I have seen many post over here but not getting solution for this.

在此先感谢... !!!

Thanks in advance...!!!

推荐答案

看起来像有一个 measureText 方法可在<一href="http://developer.android.com/reference/android/graphics/Paint.html#measureText%28java.lang.String%29"><$c$c>Paint.我还发现了一个<一个href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/MeasureText.html">example:

Looks like there is a measureText method available on Paint. I also found an example:

mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(5);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setTextSize(64);
mPaint.setTypeface(Typeface.create(Typeface.SERIF, Typeface.ITALIC));
// ...
float w = mPaint.measureText(text, 0, text.length());

这篇关于如何计算像素串字体宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆