Android interface-related classes and Android interface-related classes

Source: Internet
Author: User

Android interface-related classes and Android interface-related classes

Android interface-related classes


Activity display interface object, and added to WindowManager as the top-level View. Window provides standard UI display policies: interface Background, title area, and default event processing. This abstract class has only one subclass of PhoneWindow. During Activity creation, the ActivityThread class will execute the Activity. attach () method when calling the initiate mlaunchactivity method. This method contains the following code snippet:

// Bind the container containing Fragment to mFragments in the Activity instance. attachActivity (this, mContainer, null); // create a new Window object mWindow = PolicyManager for the Activity instance. makeNewWindow (this); mWindow. setCallback (this); mWindow. setOnWindowDismissedCallback (this); mWindow. getLayoutInflater (). setPrivateFactory (this); if (info. softInputMode! = WindowManager. LayoutParams. SOFT_INPUT_STATE_UNSPECIFIED) {mWindow. setSoftInputMode (info. softInputMode);} if (info. uiOptions! = 0) {mWindow. setUiOptions (info. uiOptions );}... // set Window Manager mWindow for the Window object. setWindowManager (WindowManager) context. getSystemService (Context. WINDOW_SERVICE), mToken, mComponent. flattenToString (), (info. flags & ActivityInfo. FLAG_HARDWARE_ACCELERATED )! = 0); if (mParent! = Null) {mWindow. setContainer (mParent. getWindow ();} mWindowManager = mWindow. getWindowManager ();

You can use the following method to obtain the interface between an application and a device Window Manager:


Each WindowManager instance is bound with a specific Display object.


A logical Display is divided into two Display areas:

  • Application Display Area: displays the Application Window, excluding system-related Display. Therefore, this Area may be smaller than the actual TV Area, you can obtain the application display area using the following methods:
Public void getSize (Point outSize); // return the size of the display area. The result is saved in outSize, in the unit of pxpublic void getRectSize (Rect outSize ); // return the rectangular area of the display area. The result is saved in outSzie, in the unit of pxpublic void getMetrics (DisplayMetrics outMetrics). // return the indicator of the display area. For details, refer to the DisplayMetrics class.
  • Real Display Area: displays the application window and system-related Display. Generally, the size of the Area is the same as that of the bound physical screen, unless Window Manager simulates displaying content on a small screen, you can use the following method to obtain the size of the area:
public void getRealSize(Point outSize);public void getRealMetrics(DisplayMetrics outMetrics);

Note: different from the physical display, the logical display can be mapped to multiple physical displays (for example, during Presentation)


This class is used to save the screen size, screen density, and font scaling. Generally, you can use the following code to obtain the objects that contain the preceding metrics:

DisplayMetrics metrics = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(metrics);

This class contains the following important fields:

Public static final int DENSITY_LOW = 120; // public static final int DENSITY_MEDIUM = 160; // default screen density: public static final int DENSITY_HIGH = 240; // public static final int DENSITY_XHIGH = 320; // public int widthPixels; // screen width, in the unit of pxpublic int heightPixels; // screen height, in the unit of pxpublic float density; // screen density (based on 160dpi). When the screen density is 120dpi, the value of this field is 0.75. When the screen density is 320dpi, the value of this field is 2 public int densityDpi; // screen density, measured in the number of pixels per inch public float xdpi; // The number of pixels per inch in the X direction public float ydpi; // number of pixels per inch in the Y direction

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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: 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.