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. There is only one subclass of the abstract class Phonewindow. During the activity creation process, the Activitythread class calls the Performlaunchactivity method and executes the Activity.attach () method, which contains the following code fragment:

    //将包含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 Device Window Manager (Windows Manager), which can be used to obtain an instance of the class as follows:

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: the region is responsible for displaying the window of the app, not the system-related display, so the area may be smaller than the actual TV area, and you can get the app display area in the following way: Application
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, typically 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, You can get the size of the zone 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 (e.g. at presentation)

Displaymetrics

Class for saving screen size, screen density, font scaling, and generally get the class object containing the above indicators by using the following code:

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

The class contains 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方向上每英寸像素点的个数

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.