Android并计算给定字体和字体大小的单行字符串的大小?

前端之家收集整理的这篇文章主要介绍了Android并计算给定字体和字体大小的单行字符串的大小?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有一种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.
原文链接:https://www.f2er.com/android/316442.html

猜你在找的Android相关文章