Android下如何计算要显示的字符串所占的宽度和高度
2016-06-17 14:35
393 查看
查询了google发现在android一下有几种方法可以做到,但是经过实际测试发现下面这种方法是最准确的
转自:http://www.cnblogs.com/error404/archive/2013/01/25/2876888.html
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());
转自:http://www.cnblogs.com/error404/archive/2013/01/25/2876888.html
相关文章推荐
- Picasso设置圆角
- Android传感器(五):线性加速度传感器
- Android数据存储之External Storage外部存储
- android点击事件的分发过程
- Android事件处理
- Android 样式
- Android传感器(四):距离传感器
- Android 读写文件整理
- Android中findViewById获取控件返回为空问题怎么解决
- 安卓获取图片缩略图的两种方式
- Android中Selsetor基本使用三,选中时改变CheckBox背景
- Android 实现模糊半透明效果的简单实现
- Android 短信的备份
- Android学习笔记六之Service二
- Fragment 重叠(重影)问题
- AndroidGUI27中findViewById返回null的快速解决办法
- android listview系列之初步接触listview(二)
- Android传感器(三):方向传感器
- android沉浸式状态栏
- 两台Android机子Adb连接