查询了google发现在android一下有几种方法可以做到,但是经过实际测试发现下面这种方法是最准确的
Rect bounds = new Rect();String text = "Hello World";TextPaint paint;paint = findViewById(R.id.hello_world).getPaint();paint.getTextBounds(text, 0, text.length(), bounds);int width = bounds.width();


Paint pFont = new Paint();Rect rect = new Rect();pFont.getTextBounds("豆", 0, 1, rect);Log.v(TAG, "height:"+rect.height()+"width:"+rect.width());

更多相关文章

  1. Android(安卓)学习笔记
  2. API 23 找不到 org.apache.http.HttpResponse;
  3. android TextView 不显示文字
  4. android 获取实际view 宽度高度
  5. cocoscreator构建的android工程报错
  6. 【android】解决在图库中缩略图与实际图片不对应的问题
  7. Android(安卓)添加同名通讯录自动合并的问题
  8. Android获取IPV4的方法
  9. Android编译出现DSL element android.dataBinding.enabled is ob

随机推荐

  1. TextView属性大全+单行显示长文本
  2. Android(安卓)NDK开发基础-------环境搭
  3. Settings: android 组件如何响应语言变化
  4. Android中的Intent[转]
  5. Android开机LOG
  6. Android(安卓)ApiDemos示例解析(91):OS->
  7. Android应用开发提高系列(5)――Android动
  8. android号码匹配位数修改
  9. 【Android(安卓)开发】:UI控件之 ListView
  10. Android(安卓)SDK与API版本的对应关系