Android obtains the physical size of a device.

Source: Internet
Author: User

Get the physical size of the device. Note that it is not the resolution!

The answer http://stackoverflow.com/questions/2193457/is-there-a-way-to-determine-android-physical-screen-height-in-cm-or-inches found from a foreign post

  
 
Displaymetrics dm = new displaymetrics (); getwindowmanager (). getdefadisplay display (). getmetrics (DM); Double X = math. pow (DM. widthpixels/DM. xdpi, 2); Double Y = math. pow (DM. heightpixels/DM. ydpi, 2); double screeninches = math. SQRT (x + y); log. D ("debug", "screen inches:" + screeninches );

 

Another section:

According to the documentation:

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 (for example a 240x320, 1.5 "x 2" screen ), providing the baseline of the system's display. thus
On a 160 DPI screen this density value will be 1; on a 120 DPI screen it wocould be. 75; etc.

This value does not exactly follow the real screen size (as given by xdpi and ydpi, but rather is used to scale the size of the overall UI in steps based on gross changes in the display DPI. for example, a 240x320 screen will have a density of 1 even if
its width is 1.8 ", 1.3", etc. however, if the screen resolution is increased to 320x480 but the screen size remained 1.5 "x 2" then the density wocould be increased (probably to 1.5 ).

Related Article

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.