Android并计算给定字体和字体大小的单行字符串的大小? [英] Android and calculating the size of a one-line string in a given font and font size?

查看:188
本文介绍了Android并计算给定字体和字体大小的单行字符串的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在API方法来计算以一行和给定字体和字体大小显示的字符串的大小(即宽度和高度)?

Is there an API method for calculating the size (i.e. width and height) of a string displayed on one line and in a given font and font size?

推荐答案

Paint p = new Paint();
p.setTypeface(TypeFace obj); // if custom font use `TypeFace.createFromFile`
p.setTextSize(float size);
float textWidth = p.measureText("Your string"); 
// you get the width here and textsize is the height.

这篇关于Android并计算给定字体和字体大小的单行字符串的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆