Android gets the phone screen size

Source: Internet
Author: User

Develop mobile appsProgramIn addition to the underlying understanding of the API, the most important thing is the screen resolution concept of ligala, because various mobile phone manufacturers use different screen sizes, the presentation and layout of the UI interfaces are also quite different.

Android can be set to adjust the scaling ratio with the window size. However, even so, mobile phone programmers must still be aware of the boundary of the mobile phone screen to avoid layout deformation caused by scaling, the following is a small example. You only need a few words to get the resolution of the mobile phone. The most important thing is the displaymetrics application.

Metrics ['metriks] measurement, measurement

Heightpixels: displays absolute pixels of height.

Widthpixels: absolute pixel of display width

 Package Org. hualang. Other; Import Android. App. activity; Import Android. content. res. Resources; Import Android. Graphics. drawable. drawable; Import Android. OS. Bundle;Import Android. util. displaymetrics; Import Android. widget. textview; Public     Class Other Extends Activity { /** Called when the activity is first created .*/          Private Textview text1, text2; @ override Public     Void Oncreate (bundle savedinstancestate ){ Super . Oncreate (savedinstancestate); setcontentview (R. layout. Main );// Android. util. displaymetrics must be referenced Displaymetrics dm = New Displaymetrics (); getwindowmanager (). getdefadisplay display (). getmetrics (DM); string stropt =" Cell phone screen resolution: "+ DM. widthpixels +" X "+ DM. heightpixels; text1 = (textview) findviewbyid (R. Id. text1); text1.settext (stropt );}}
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.