【鸿蒙HarmonyOS开发】获取布局大小、屏幕尺寸
获取布局的大小布局对象.getLayoutConfig().width布局对象.getLayoutConfig().height
·
长度单位基本概念
px 屏幕硬件的像素单位
vp 虚拟像素,适应不同屏幕密度的显示效果。
fp 字体像素单位,字体像素大小与虚拟像素大小相同。如果在设置中选择较大的字体大小,实际字体大小为虚拟像素大小乘以比例系数。也就是说,1 fp = 1 vp * 比例。
px、vp、fp可以利用AttrHelper工具类进行转换。
获取布局的大小(px)
- 布局对象.getLayoutConfig().width
- 布局对象.getLayoutConfig().height
- 布局对象.getWidth()
- 布局对象.getHeight()
屏幕大小(vp)
屏幕虚拟像素:
- getContext().getResourceManager().getDeviceCapability().width
- getContext().getResourceManager().getDeviceCapability().height
屏幕密度:
- getContext().getResourceManager().getDeviceCapability().screenDensity
更多推荐
所有评论(0)