Android interface-related classes

Source: Internet
Author: User

Android interface-related classes

Window

The activity's display interface object, and is added to the WindowManager as a top-level view. Window provides a standard UI display policy: interface background, title area, default event handling.

The abstract class has only one subclass of Phonewindow. During the activity creation process, the Activitythread class calls the Performlaunchactivity method and runs the Activity.attach () method, which includes the following code snippet:

    //将包括Fragment的容器绑定到Activity实例中    mFragments.attachActivity(this, mContainer, null);    //为Activity实例创建一个新的Window对象    mWindow = PolicyManager.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);    }    ...    //为Window对象设置Window Manager    mWindow.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();
WindowManager

An interface that interacts with the application and Device Forms Manager (Window Manager) to obtain an instance of the class by, for example, the following:

Context.getSystemServier(Context.WINDOW_SERVICE);

Each WindowManager instance is bound to a specific display object.

Display

Represents a logical display (logical display), which is divided into two types:

  • App display area (application display areas): This area is responsible for displaying the window of the app, excluding system-related displays. So the area is likely to be smaller than the actual TV area and can be used for example to get the application display area:
public void getSize(Point outSize);  //返回显示区域的大小,结果保存在outSize中。单位为pxpublic void getRectSize(Rect outSize);  //返回显示区域的矩形区域,结果保存在outSzie中,单位为pxpublic void getMetrics(DisplayMetrics outMetrics); // 返回显示区域的指标。详细能够查阅DisplayMetrics类
  • Actual display area: The area shows the window and system-related display of the app, in general, the size of the area and the physical screen size of the binding, unless the window manager simulates displaying the content on a small screen, The size of the zone can be obtained in the following ways:
public void getRealSize(Point outSize);public void getRealMetrics(DisplayMetrics outMetrics);

Note: Unlike the physical display, the logic display can be mapped to multiple physical displays (for example, at presentation)

Displaymetrics

A class for saving screen size, screen density, font scaling, and generally the following code to get the class object that includes the above indicator:

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

This class includes the following more important fields:

public static final int DENSITY_LOW = 120;   //public static final int DENSITY_MEDIUM = 160;  // 默认的屏幕密度public static final int DENSITY_HIGH = 240;  //public static final int DENSITY_XHIGH = 320;  //public int widthPixels; //屏幕的宽度,单位为pxpublic int heightPixels; //屏幕的高度。单位为pxpublic float density; //屏幕密度(以160dpi为基准),当屏幕密度为120dpi时。该字段的值为0.75。当屏幕密度为320dpi时。该字段的值为2public int densityDpi; //屏幕密度,单位为每英寸的像素点个数public float xdpi; //X方向上每英寸像素点的个数public float ydpi; //Y方向上每英寸像素点的个数

Android interface-related classes

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.