是否有一种 API 方法可以计算在一行中以给定字体和字体大小显示的字符串的大小(即宽度和高度)?
最佳答案
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并计算给定字体和字体大小的单行字符串的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7329004/