[Android Basics] Get Mobile Phone resolution

Source: Internet
Author: User

In the development of mobile apps, in addition to understanding the API, more important is the screen.

Screen Resolution is an important factor for images. Because the cell phone screen sizes are different, you need to consider this issue during screen layout.

Android can be set to adjust the zoom ratio with the window size, but even so, the mobile phone program designer must still know the cell phone screen boundary to avoid layout deformation.

Next, let's talk about how to get the resolution of the mobile phone screen through code. The code is actually very simple. The key is the Android. util. displaymetrics class. This class records some common information, such as the display information, size, dimension, Font, and so on.

Code:

@ Override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/>/* load page */<br/> setcontentview (R. layout. main); </P> <p>/* References android. util. displaymetrics */<br/> displaymetrics dm = new displaymetrics (); <br/> getwindowmanager (). getdefadisplay display (). getmetrics (DM); </P> <p> int width = DM. widthpixels; <br/> int Height = DM. heightpixels; </P> <p> button = (button) findviewbyid (R. id. b01); <br/> button. settext ("cell phone screen resolution:" + width + "*" + height); <br/>} 

Effect:

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.