Units and measurements - 自适应准则
Some units have different meanings in different contexts. This chapter discusses the usage of device-independent pixels, scaleable pixels, as well as concepts like pixel density.
【翻译】
一些单位在不同的语境中有不同的含义。 本章讨论设备无关像素,可缩放像素的使用,以及像像素密度的概念。
Pixel density - 像素密度
The number of pixels that fit into an inch is referred to as “pixel density.” High-density screens have more pixels per inch than low-density ones. As a result, UI elements (such as a button) appear physically larger on low-density screens and smaller on high-density screens.
【翻译】
一英寸所包含像素数被称为“像素密度”。高密度屏幕每英寸具有比低密度屏幕更多的像素。 因此,UI元素(例如按钮)在低密度屏幕上显得更大,而在高密度屏幕上更小。
Screen resolution refers to the total number pixels in a display.
【翻译】
屏幕分辨率是指显示屏中像素的总数。
screen density = screen width (or height) in pixels / screen width (or height) in inches
【翻译】
屏幕密度=屏幕宽度(或高度)(以像素为单位)/屏幕宽度(或高度)(以英寸为单位)
High-density screen
【翻译】
高密度屏幕
【翻译】
低密度屏幕
Density-independent pixels (dp) - 密度独立像素(dp)
"Density independence" refers to the uniform display of UI elements on screens with different densities.
【翻译】
“密度独立性”是指在具有不同密度的屏幕上UI元素的均匀显示。
Density-independent pixels (pronounced “dips”) are flexible units that scale to uniform dimensions on any screen. When developing an Android application, use dp to display elements uniformly on screens with different densities.
【翻译】
密度独立像素是在任何屏幕上缩放至统一尺寸的灵活单位。在开发Android应用程序时,使用dp在不同密度的屏幕上统一显示元素。
A dp is equal to one physical pixel on a screen with a density of 160. To calculate dp:
dp = (width in pixels * 160) / screen density
When writing CSS, use px wherever dp or sp is stated. Dp only needs to be used in developing for Android.
【翻译】
dp等于屏幕上密度为160的一个物理像素。要计算dp: dp =(像素的宽度* 160)/屏幕密度
当编写CSS时,使用px,无论dp或sp是什么。 Dp只需要在Android的开发中使用。
If you have three screens, all 1.5 inches wide, with varying screen densities, the screen width will still be 240dp for all of them.
【翻译】
如果你有三个屏幕,所有1.5英寸宽,具有不同的屏幕密度,所有屏幕屏幕宽度仍将为240dp。
Scaleable pixels (sp) - 可缩放像素
When developing for Android, scaleable pixels (sp) serve the same function as dp, but for fonts. The default value of an sp is the same as the default value for dp.
【翻译】
当为Android开发时,可缩放像素(sp)提供与dp相同的功能,作用于字体。 sp的默认值与dp的默认值相同。
The primary difference between an sp and a dp is that sp preserves a user's font settings. Users who have larger text settings for accessibility will see the font size matched to their text size preferences.
【翻译】
sp和dp之间的主要区别是sp保留了用户的字体设置。具有较大文字设置以供辅助功能的用户将看到与其文字大小首选项匹配的字体大小。
Designing layouts for dp - 以dp设计布局
When designing layouts for the screen, calculate an element’s measurements in dp:
dp = (width in pixels * 160) / density
For example, a 32 x 32 px icon with a screen density of 320 equals 16 x 16 dp.
【翻译】
当设计屏幕的布局时,计算元素的度量dp:
dp =(宽度的像素数* 160)/密度
例如,屏幕密度为320的32 x 32像素图标等于16 x 16 dp。
Image scaling - 图像缩放
Images can be scaled to look the same across different screen resolutions by using these ratios:
【翻译】
通过使用以下比率,图像可以缩放以在不同的屏幕分辨率之间看起来相同:
网友评论