In Android development, you often need to obtain the screen size of the mobile phone. The common method is to use the displaymetrics class to obtain the screen width and height of the mobile phone. The sample code is as follows:
Package whu. ISS. wuxianglong; import android. app. activity; import android. OS. bundle; import android. util. displaymetrics; import android. widget. textview; public class getscreensize extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); displaymetrics displaysmetrics = new displaymetrics (); getwindowmanager (). getdefadisplay display (). getmetrics (displaysmetrics); string showsize = "cell phone screen resolution:" + displaysmetrics. widthpixels + "*" + displaysmetrics. heightpixels; textview screensize = (textview) findviewbyid (R. id. size); screensize. settext (showsize );}}
The running result is as follows:
The end!