android 计算字符宽度

wc7253027 2011-12-20 11:48:33
一个字符串,怎样计算他在屏幕中所占的宽度
...全文
454 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
独领风骚的猫 2012-07-16
  • 打赏
  • 举报
回复
font.measureTextWidth()
戏谑 2012-07-12
  • 打赏
  • 举报
回复
上面那个试了试,可以获得字符串的宽度
booooo­ 2011-12-20
  • 打赏
  • 举报
回复
J2ME中:
Font.stringWidth(String str);
Android中
字符串宽度可以这样:
Paint paint = new Paint();
float strWidth = paint.measureText(String);
paint.setTextSize(tv.getTextSize());
二.
private final Paint pFont = new Paint();
Rect rect = new Rect();
pFont.getTextBounds("小", 0, 1, rect);
Log.v(TAG, "height:"+rect.height()+"width:"+rect.width());
这是android的,你试一下
传说这个方法能解决问题
http://topic.csdn.net/u/20101112/13/13ef18f7-7665-4639-9094-4f42c338e0c2.html

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧