How to get the device's wide height in Android

Source: Internet
Author: User

Before Android 4.0, you can get the width of the screen in the following way:

Displaymetrics dm = new Displaymetrics ();

Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);

int Mscreenw = dm.widthpixels; Get width

int mscreenh = dm.heightpixels; Get high

By the above method before 4.0, the total width and total height of the screen, including the height of the status bar and the height of the navigation bar, such as a 480 * 800 device, the above method to obtain the value is 480 and 800, However, after 4.0, the above method gets the height that is removed from the height of the navigation bar, for example, if the height of the navigation bar is 48, the value of the mscreenh obtained by the above method after 4.0 is equal to 480-48 = 432.


Therefore, if you want to get the total height of the screen after 4.0, you need to use the following method:

Display display = Getwindowmanager (). Getdefaultdisplay ();
Point point = new Point ();
display.getrealsize (point);
int mscreenh = POINT.Y;

int mscreenw = Point.x;

The wide height obtained is 480 and 800.

Note: We do the car, so the size is the size of the horizontal screen.

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.