Android dpi, dip, PX, resolution, screen size, density relationships, and conversions

Source: Internet
Author: User

First, Introduction

  • Dip: device independent pixels (devices independent pixel), an abstract unit based on density;


  • DP: in earlier versions of Android, the use of dip, and later in order to unify with the SP recommended the use of the name DP;


  • px: Pixel (Pixel), 1px represents a physical pixel on the screen, PX units are not recommended, because the same 1px, the actual size of the display on different phones may be different, the occasional use of PX is to draw a 1-pixel table line or draw a thin dividing line , In other units such as DP will appear blurred;


  • SP: " 1sp=1dp=0.00625" when the text size is set to "large" or "oversized", 1sp>1dp=0.00625 inches;


  • DPI: number of pixels per inch (dots per inch  ), a common value of 120,160,240 pixel density, referred to as density;


  • Density: density. Common values are 1.5, 1.0. Proportional to the standard dpi (160px/inc)


  • Resolution: number of pixel points in 2 directions, common value 480X800, 320X480


  • Screen Size: the length of the screen diagonal. Computer TV is the same.

Second, conversion

    dip = (dpi/160) *pixel. (so dip may be larger or smaller than pixels)

    /**     * dp  units   turn into  px (pixels)       *      *  @param  context      *  @param  dpValue     *  @return      */     PUBLIC STATIC INT DIP2PX (Context context, float dpvalue)  {        final float scale =  Context.getresources (). Getdisplaymetrics (). Density;        return   (int)   (dpvalue * scale + 0.5f);    }     /**     *  from  px (pixels)     go to  dp      *      *  @param  context     * @ param pxvalue     *  @return      */    public static int px2dip ( Context context, float pxvalue)  {        final  float scale = context.getresources (). Getdisplaymetrics () .density;         return  (int)   (pxvalue / scale + 0.5f);     }

Android,

in 160dpi (MDPI), 1 dip = 1 px;
In 120dpi (ldpi), 1 dip = 0.75px;
      In 240dpi (hdpi), 1 dip = 1.5px;
      in 320dpi (xhdpi), 1dip = 2px;


Third, the adaptation in Android

In the following directory for each resolution, you can do different mobile phone matching

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/BE/wKiom1WEGKWxNs_IAABk0ZIRS5Q517.jpg "style=" float: none; "title=" Qq20150619212115.png "alt=" Wkiom1wegkwxns_iaabk0zirs5q517.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/BE/wKiom1WEGKWjPATLAABIRejWVbY777.jpg "style=" float: none; "title=" Qq20150619212258.png "alt=" Wkiom1wegkwjpatlaabirejwvby777.jpg "/>

I use the following tools to look at the artwork, as below, you can switch the different resolutions

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6E/BE/wKiom1WEHkuApTMvAAMCLZvW5jU782.jpg "title=" Qq20150619215046.png "alt=" Wkiom1wehkuaptmvaamclzvw5ju782.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/BB/wKioL1WEID7RDpPQAALvRXB0id8441.jpg "title=" Qq20150619215156.png "alt=" Wkiol1weid7rdppqaalvrxb0id8441.jpg "/>

Android dpi, dip, PX, resolution, screen size, density relationships, and conversions

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.