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.