Android development: PX and DP, SP conversion formula? (ZZ)

Source: Internet
Author: User

PPI = Pixels per inch, number of pixels on average, "pixel density"

    • xhdpi:2.0
    • hdpi:1.5
    • mdpi:1.0 (Baseline)
    • ldpi:0.75

DRAWABLE-LDPI, drawable-mdpi, drawable-hdpi accuracy are low, medium (Android default), high.
The corresponding image sizes are: 36x36, 48x48, 72x72.

xxhdpi:144*144
xhdpi:96*96
hdpi:72*72
mdpi:48*48
Ldpi:36*36

DP is a virtual pixel that is automatically adapted to devices with different pixel densities, such as:
At 320x480 resolution, pixel density is 160,1dp=1px
At 480x800 resolution, pixel density is 240,1dp=1.5px
Calculation formula: 1dp* pixel density/160 = actual number of pixels

The difference between drawable-hdpi, drawable-mdpi and drawable-ldpi:
(1) drawable-hdpi contains high-resolution images, such as WVGA (480x800), FWVGA (480x854)
(2) drawable-mdpi contains medium-resolution images, such as HVGA (320x480)
(3) drawable-ldpi contains low-resolution images, such as QVGA (240x320)
The system will be based on the resolution of the machine to each of these folders to find the corresponding picture.

the PPI is calculated as:

PPI =√ (length pixels 2 + width pixel number 2)/Screen diagonal inches

Dp:density-independent pixels, with 160PPI screen as standard, then 1dp=1px,

Conversion formulas for DP and PX:
dp*ppi/160 = px. such as 1DP x 320ppi/160 = 2px.

Sp:scale-independent pixels, which is the font unit for Android, is the standard 160PPI screen, when the font size is 100%, 1sp=1px.

conversion formula for SP and px : sp*ppi/160 = px

It concludes that:

PX = dp*ppi/160
dp = px/(ppi/160)

PX = sp*ppi/160
sp = px/(ppi/160)

DP = SP?


Source: http://www.cnblogs.com/bluestorm/p/3640786.html

From for notes (Wiz)

Android development: PX and DP, SP conversion formula? (ZZ)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.