Why Android doesn't calculate the exact screen size, and Android gets screen physical size, density, and resolution

Source: Internet
Author: User

Dpi:dots-per-inch, the number of pixels per inch, that is, the greater the density, the more points are accommodated in each inch. This value is determined by the device itself and written to death.

Calculation method: Get to the screen resolution: Point.x and POINT.Y, then take out the screen dpi (number of pixels per inch), calculate the length and width of how many inches, that is: Point.x/dm.xdpi,point.y/ DM.YDPI, the length and width of the screen is calculated, and then using the Pythagorean theorem, calculate the angle of the bevel edge, that is, the screen size.

WindowManager manager = (WindowManager) context.getsystemservice (context.window_service);D isplaymetrics Displaysmetrics = new Displaymetrics (); Manager.getdefaultdisplay (). Getmetrics (Displaysmetrics); Point point = new Point (), Manager.getdefaultdisplay (). Getrealsize (point);D isplaymetrics dm = context.getresources (). Getdisplaymetrics ();d ouble x = Math.pow (point.x/dm.xdpi, 2);d ouble y = Math.pow (point.y/dm.ydpi, 2);d ouble ScreenInche s = math.sqrt (x + y);
Note: Here Displaymetrics do not use Context.getapplicationcontext (). Getresources (). Getdisplaymetrics () to get.

As mentioned above, DPI is written to the device from the factory, if the DPI value is not accurate, of course, does not calculate the exact screen size. That's why there's no screen size in the league stats, so the calculated screen size is only a reference.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Why Android doesn't calculate the exact screen size, and Android gets screen physical size, density, and resolution

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.