Android下如何计算要显示的字符串所占的宽度和高度
16lz
2022-06-06
查询了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());
更多相关文章
- Android(安卓)学习笔记
- API 23 找不到 org.apache.http.HttpResponse;
- android TextView 不显示文字
- android 获取实际view 宽度高度
- cocoscreator构建的android工程报错
- 【android】解决在图库中缩略图与实际图片不对应的问题
- Android(安卓)添加同名通讯录自动合并的问题
- Android获取IPV4的方法
- Android编译出现DSL element android.dataBinding.enabled is ob