简体   繁体   English

Android的DisplayMetrics类中的scaledDensity和density有什么区别?

[英]what is the difference between scaledDensity and density in Android`s DisplayMetrics class?

TextView compute text size value with scaledDensity instead of density. TextView使用scaledDensity代替密度来计算文本大小值。 so what`s the difference between these two values? 那么这两个值有什么区别?

DisplayMetrics#scaledDensity

A scaling factor for fonts displayed on the display. 显示屏上显示的字体的比例因子。 This is the same as density, except that it may be adjusted in smaller increments at runtime based on a user preference for the font size. 这与密度相同,除了可以在运行时根据用户对字体大小的偏好以较小的增量进行调整。

DisplayMetrics#Density

The logical density of the display. 显示的逻辑密度。 This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen. 这是密度独立像素单位的比例因子,其中一个DIP是大约160 dpi屏幕上的一个像素。

sp SP

Scale-independent Pixels – this is like the dp unit, but it is also scaled by the user's font size preference. 与缩放无关的像素–就像dp单位一样,但是它也通过用户的字体大小首选项进行缩放。 It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference. 建议您在指定字体大小时使用本机,以便针对屏幕密度和用户喜好进行调整。

dp DP

A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way. 在定义UI布局时应使用的虚拟像素单位,以密度独立的方式表示布局尺寸或位置。

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a “medium” density screen. 与密度无关的像素等效于160 dpi屏幕上的一个物理像素,这是系统为“中”密度屏幕假定的基线密度。

you can find nice explanation here Difference of px, dp, dip and sp in Android and Android units 您可以在此处找到很好的解释AndroidAndroid单位 中px,dp,dip和sp的差异

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DisplayMetrics.scaledDensity 在 Android 中实际返回什么? - What does DisplayMetrics.scaledDensity actually return in Android? Android:分辨率和密度有什么区别? - Android: what is the difference between resolution and density? 是什么导致Android的DisplayMetrics.densityDpi在Release版本和Debug版本之间有所不同? - What could cause Android's DisplayMetrics.densityDpi to differ between Release and Debug builds? Android的密度桶之间究竟有什么界限? - What exactly are the boundaries between Android's Density Buckets? 如何在android单元测试中模拟Resources类以获得scaledDensity? - How to mock the Resources class in android unit test in order to get the scaledDensity? Class &lt;*&gt;和Class有什么区别<T> - What's the difference between Class<*> and Class<T> Android中“屏幕尺寸”和“屏幕密度”之间的区别? - Difference between “screen size” and “screen density” in Android? Android中的活动和意图有什么区别? - What's the difference between activity and intent in Android? Android 4和Android 5中的BringToFront有什么区别? - What's the difference between bringToFront in Android 4 and Android 5? windowActionBar和android:windowActionBar之间的区别是什么 - what's the difference between windowActionBar and android:windowActionBar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM