How Android Gets a wide screen height

Source: Internet
Author: User

1. Implementing the Code

        Private intMwidth; Private intMheight; @TargetApi (build.version_codes. JELLY_BEAN_MR1) Public voidGetdisplaymetrics () {WindowManager wm=(WindowManager) Mcontext.getsystemservice (Context.window_service); Display Display=Wm.getdefaultdisplay (); intApi_level =Android.os.Build.VERSION.SDK_INT; //Method 1Displaymetrics Displaymetrics =NewDisplaymetrics (); if(Api_level >= 17) {display.getrealmetrics (displaymetrics); } Else{display.getmetrics (displaymetrics); } mwidth=Displaymetrics.widthpixels; Mheight=Displaymetrics.heightpixels; //Method 2Point outsize =NewPoint (); if(Api_level >= 17) {display.getrealsize (outsize); } Else{display.getsize (outsize); } mwidth=outsize.x; Mheight=outsize.y; //Method 3Mwidth =mcontext.getresources (). Getdisplaymetrics (). Widthpixels; Mheight=mcontext.getresources (). Getdisplaymetrics (). Heightpixels; }

2. Description

Display

Provides information about the size and density of a logical display.

The display area was described in and different ways.

  • The application display area specifies the part of the display, the contain an application window, excluding the system decorations. The application display area is smaller than the real display area because the system su Btracts the space needed for decor elements such as the status bar. Use the following methods to query the application display area:  getsize (Point) ,   Getrectsize (Rect)  and  getmetrics (Displaymetrics) .
  • The real display area specifies the part of the display contains content including the system decorations. E Ven so, the real display area could be smaller than the physical size of the display if the Windows Manager is emulating a SM Aller display using (adb shell am display-size). Use the following methods to query the real display area: getRealSize(Point) , getRealMetrics(DisplayMetrics) .

3. Note

Public void getrealmetrics (displaymetrics outmetrics) Added in API level

Gets display metrics based on the real size of this display.

The size is adjusted based on the current rotation of the display.

The real size may be smaller than the physical size of the "when" window manager is emulating a smaller display ( Using adb shell am display-size).

Public void getrealsize (point outsize) Added in API level

Gets the real size of the display without subtracting any window decor or applying any compatibility scale factor S.

The size is adjusted based on the current rotation of the display.

The real size may be smaller than the physical size of the "when" window manager is emulating a smaller display ( Using adb shell am display-size).

How Android Gets a wide screen height

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.