zoukankan      html  css  js  c++  java
  • Android界面相关的类

    Android界面相关的类

    Window

    Activity的显示界面对象,并作为顶层View被加入到WindowManager中。Window提供了标准的UI显示策略:界面背景、标题区域、默认的事件处理。

    该抽象类仅仅有一个子类PhoneWindow。在Activity的创建过程中,ActivityThread类调用performLaunchActivity方法时会运行Activity.attach()方法,该方法包括以下的代码片段:

        //将包括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

    应用和设备窗体管理器(Window Manager)交互的接口,能够通过例如以下方式获取该类实例:

    Context.getSystemServier(Context.WINDOW_SERVICE);
    

    每一个WindowManager实例都和一个特定的Display对象绑定在一起。

    Display

    代表一个逻辑显示屏(logical Display),显示区域被划分成两种:

    • 应用显示区域(Application Display Area):该区域负责显示应用的Window,不包括系统相关的显示。所以该区域有可能会比实际电视区域小,能够通过例如以下方法获取应用显示区域:
    public void getSize(Point outSize);  //返回显示区域的大小,结果保存在outSize中。单位为px
    
    public void getRectSize(Rect outSize);  //返回显示区域的矩形区域,结果保存在outSzie中,单位为px
    
    public void getMetrics(DisplayMetrics outMetrics); // 返回显示区域的指标。详细能够查阅DisplayMetrics类
    
    • 实际显示区域(Real Display Area): 该区域显示应用的window和系统相关的显示,普通情况下,该区域大小和绑定的物理屏幕大小同样,除非Window Manager模拟将内容显示在小屏幕上,能够通过以下的方法获取该区域的大小:
    public void getRealSize(Point outSize);
    
    public void getRealMetrics(DisplayMetrics outMetrics);
    

    注意:逻辑显示屏和物理显示屏不同,逻辑显示屏能够被映射到多个物理显示屏上(比方在Presentation的时候)

    DisplayMetrics

    用于保存屏幕大小,屏幕密度,字体缩放的类,一般通过以下的代码获取包括上述指标的该类对象:

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

    该类中包括以下比較重要的字段:

    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; //屏幕的宽度,单位为px
    public int heightPixels; //屏幕的高度。单位为px
    
    public float density; //屏幕密度(以160dpi为基准),当屏幕密度为120dpi时。该字段的值为0.75。当屏幕密度为320dpi时。该字段的值为2
    
    public int densityDpi; //屏幕密度,单位为每英寸的像素点个数
    
    public float xdpi; //X方向上每英寸像素点的个数
    public float ydpi; //Y方向上每英寸像素点的个数
    
  • 相关阅读:
    JVM源码分析 规格严格
    Smack 规格严格
    Java动态编译 规格严格
    RPM仓库地址 规格严格
    使用控制台程序测试DLL依赖
    TestNG 使用入门
    白羊座二:星星的一周
    路遇两骗子
    《落地,请开手机》里面最经典的一句台词
    今天明白的一个道理
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7121009.html
Copyright © 2011-2022 走看看