android 获取字体宽高

简介: 引用:http://www.4ucode.com/Study/Topic/910199 字体样式大小都是用Paint类定义的。 public void getTextBounds(String text, int start, int end, Rect bounds)Return in bou...

引用:http://www.4ucode.com/Study/Topic/910199

字体样式大小都是用Paint类定义的。

public void getTextBounds(String text, int start, int end, Rect bounds)
Return in bounds (allocated by the caller) the smallest rectangle that encloses all of the characters, with an implied origin at (0,0).
Parameters
text String to measure and return its bounds
start Index of the first char in the string to measure
end 1 past the last char in the string measure
bounds Returns the unioned bounds of all the text. Must be allocated by the caller.

比如:
private final Paint pFont = new Paint();
Rect rect = new Rect();
pFont.getTextBounds(“辉”, 0, 1, rect);
Log.v(TAG, “height:”+rect.height()+”width:”+rect.width());

相关文章
|
API Android开发
Android 自定义最大宽度,高度, 宽高比例 Layout
Android 自定义最大宽度,高度, 宽高比例 Layout
|
Android开发
Android 自带的字体库、字体样式
Android 自带的字体库、字体样式
1751 0
Android 自带的字体库、字体样式
|
Android开发
Android面试题经典之如何全局替换App的字体
在Android应用中替换字体有全局和局部方法。全局替换涉及在`Application`的`onCreate`中设置自定义字体,并创建新主题。局部替换则可在布局中通过`ResourcesCompat.getFont()`加载字体文件并应用于`TextView`。
231 2
|
Android开发 开发者
Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。
【6月更文挑战第26天】Android UI设计中,Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等,定义在`styles.xml`。要更改主题,首先在该文件中创建新主题,如`MyAppTheme`,覆盖所需属性。然后,在`AndroidManifest.xml`中应用主题至应用或特定Activity。运行时切换主题可通过重新设置并重启Activity实现,或使用`setTheme`和`recreate()`方法。这允许开发者定制界面并与品牌指南匹配,或提供多主题选项。
234 6
|
Android开发 开发者
Android UI中的Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等。要更改主题
【6月更文挑战第25天】Android UI中的Theme定义了Activity的视觉风格,包括颜色、字体、窗口样式等。要更改主题,首先在`styles.xml`中定义新主题,如`MyAppTheme`,然后在`AndroidManifest.xml`中设置`android:theme`。可应用于全局或特定Activity。运行时切换主题需重置Activity,如通过`setTheme()`和`recreate()`方法。这允许开发者定制界面以匹配品牌或用户偏好。
232 2
|
Android开发
Android 自定义View 测量控件宽高、自定义viewgroup测量
Android 自定义View 测量控件宽高、自定义viewgroup测量
513 0
|
开发工具 Android开发 git
Android自定义View——可以设置最大宽高的FrameLayout
Android自定义View——可以设置最大宽高的FrameLayout
469 0
|
JSON Android开发 数据格式
Android动态添加view设置view大小(宽高)
Android动态添加view设置view大小(宽高)
291 0
|
XML 搜索推荐 Java
Android TextView的字体设置
【5月更文挑战第13天】
752 0
|
XML Java Android开发
Android Studio中视图基础之设置视图的宽高、间距、对齐方式的讲解与实战(附源码 超详细必看)
Android Studio中视图基础之设置视图的宽高、间距、对齐方式的讲解与实战(附源码 超详细必看)
766 0