Units and measurements - 自適應(yīng)準(zhǔn)則
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.
【翻譯】
一些單位在不同的語境中有不同的含義量九。 本章討論設(shè)備無關(guān)像素咒程,可縮放像素的使用弥搞,以及像像素密度的概念。
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.
【翻譯】
一英寸所包含像素?cái)?shù)被稱為“像素密度”超歌。高密度屏幕每英寸具有比低密度屏幕更多的像素墓贿。 因此祥款,UI元素(例如按鈕)在低密度屏幕上顯得更大较锡,而在高密度屏幕上更小。
Screen resolution refers to the total number pixels in a display.
【翻譯】
屏幕分辨率是指顯示屏中像素的總數(shù)伏钠。
screen density = screen width (or height) in pixels / screen width (or height) in inches
【翻譯】
屏幕密度=屏幕寬度(或高度)(以像素為單位)/屏幕寬度(或高度)(以英寸為單位)
High-density screen
【翻譯】
高密度屏幕
【翻譯】
低密度屏幕
Density-independent pixels (dp) - 密度獨(dú)立像素(dp)
"Density independence" refers to the uniform display of UI elements on screens with different densities.
【翻譯】
“密度獨(dú)立性”是指在具有不同密度的屏幕上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.
【翻譯】
密度獨(dú)立像素是在任何屏幕上縮放至統(tǒng)一尺寸的靈活單位。在開發(fā)Android應(yīng)用程序時(shí)熟掂,使用dp在不同密度的屏幕上統(tǒng)一顯示元素缎浇。
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的一個(gè)物理像素。要計(jì)算dp: dp =(像素的寬度* 160)/屏幕密度
當(dāng)編寫CSS時(shí)赴肚,使用px素跺,無論dp或sp是什么。 Dp只需要在Android的開發(fā)中使用誉券。
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.
【翻譯】
如果你有三個(gè)屏幕指厌,所有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.
【翻譯】
當(dāng)為Android開發(fā)時(shí),可縮放像素(sp)提供與dp相同的功能,作用于字體箕憾。 sp的默認(rèn)值與dp的默認(rèn)值相同牡借。
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之間的主要區(qū)別是sp保留了用戶的字體設(shè)置。具有較大文字設(shè)置以供輔助功能的用戶將看到與其文字大小首選項(xiàng)匹配的字體大小袭异。
Designing layouts for dp - 以dp設(shè)計(jì)布局
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.
【翻譯】
當(dāng)設(shè)計(jì)屏幕的布局時(shí)蓖捶,計(jì)算元素的度量dp:
dp =(寬度的像素?cái)?shù)* 160)/密度
例如,屏幕密度為320的32 x 32像素圖標(biāo)等于16 x 16 dp扁远。
Image scaling - 圖像縮放
Images can be scaled to look the same across different screen resolutions by using these ratios:
【翻譯】
通過使用以下比率,圖像可以縮放以在不同的屏幕分辨率之間看起來相同: