Android 中如何得到字符的像素宽度
来源:互联网 发布:vfp网络编程 编辑:程序博客网 时间:2024/06/04 13:42
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());
Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.WHITE);
// Define the string.
String displayText = “Hello World!”;
// Measure the width of the text string.
float textWidth = mTextPaint.measureText(displayText);
Paint mPaint = new Paint();
mPaint.setTextSize(16);
float FontSpace = mPaint.getFontSpacing();
return text.length()*FontSpace;
最后的结果 用字符串长度 × 字体宽度。得到字符长度最接近实际长度,但是当出现英文或者是标点符号时,长度就会缩小
条件是:在不同字体,和不同大小的情况下都可以
字符串宽度可以这样:
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());
Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.WHITE);
// Define the string.
String displayText = “Hello World!”;
// Measure the width of the text string.
float textWidth = mTextPaint.measureText(displayText);
Paint mPaint = new Paint();
mPaint.setTextSize(16);
float FontSpace = mPaint.getFontSpacing();
return text.length()*FontSpace;
最后的结果 用字符串长度 × 字体宽度。得到字符长度最接近实际长度,但是当出现英文或者是标点符号时,长度就会缩小
- Android 中如何得到字符的像素宽度
- Android中如何获取字符或者字符串的宽度
- java界面中如何得到字符串的高度和宽度
- android中得到屏幕的高宽(像素)
- Android中获取字符串长度、宽度(所占像素宽度)的方法
- 如何知道手机屏幕的CSS像素宽度?
- SWT中取得字符串的像素宽度
- 如何控制html中字符字体的宽度?
- 计算中文、英文、数字、空格的字符像素宽度
- C#中如何获取一个字体的宽度值(像素单位)
- C#中如何获取一个字体的宽度值(像素单位)?
- C#中如何得到双字节字符的ASCII码
- Android中获取当前屏幕的宽度,高度,像素密度的代码。
- android textview 中超出屏幕宽度的字符 省略号显示
- android textview 中超出屏幕宽度的字符 省略号显示
- android 中超出屏幕宽度的字符 省略号显示
- android textview 中超出屏幕宽度的字符 省略号显示
- android textview中超出屏幕宽度的字符 省略号显示
- Visual.Assist.X.V10.7.1908采用DLL覆盖破解技术. 新增了对VS2012的支持
- javascript validate
- 指针和数组的千丝万缕(三)
- C语言中如何将二维数组作为函数的参数传递
- iPhone开发 解析xml NSData xml
- Android 中如何得到字符的像素宽度
- WebBrowser控件处理url中文传值时不能转换
- 探索ORACLE之ASM概念
- Linux 下 mysql :ERROR 1040 (00000): Too many connections解决方法
- 配置solaris上网
- SQL NULL 函数
- JVM内存分配、垃圾回收、启动参数
- vim编码方面的基础知识
- C# 连接SQL数据库