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: