How to obtain the screen hardware resolution

Source: Internet
Author: User
Textview TV = (textview) findviewbyid (R. id. TV); displaymetrics dm = new displaymetrics (); getwindowmanager (). getdefadisplay display (). getmetrics (DM); float width = DM. widthpixels * DM. density; float Height = DM. heightpixels * DM. density; TV. settext (width + "X" + height );
DM. withpixels and DM. the width and height values obtained by heightpixels are both based on the width of 320. That is to say, no matter what resolution your screen is, the width of the screen will be 320, and the height is calculated based on the aspect ratio, therefore, the width and height obtained on the milestone (480X854) is 320x569. To obtain a real resolution, multiply the value by DM. density. The value varies depending on the hardware resolution. If the screen width is 320 pixels, the value is 1. If the screen width is 480, the value is 480/320, or 1.5.

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.