Android系统UI显示图层控制方法

本文探讨了Android系统中UI显示图层的控制,主要涉及WindowManager和LayoutParams的角色。通过调整Window的类型和布局属性,可以实现不同界面的图层优先级设置。此外,介绍了使用adb shell命令来查看Window的layer,如`dumpsys -l`、`dumpsys window`和`dumpsys SurfaceFlinger`,以帮助理解界面的显示顺序。
摘要由CSDN通过智能技术生成

        做系统层开发,往往会遇到UI显示图层的一些设置,比如一些界面可以直接被其他界面遮挡,有些界面只能被部分界面遮挡,甚至有些界面需要置顶不被任何界面遮挡;每个界面就是一个Window(窗口),是Window就受WindowManager管理,WindowManager中存在对应的LayoutParams(布局属性),通过设置这些属性可以控制Window的类型,Window的类型中自然就包含其显示图层的控制。

        说到这儿我还想谈谈自己对Window的理解,顾名思义它就是一个窗口,这个窗口里面可以包含一些布局,布局中又可以包含一些View控件,整个组成一个可以展示出来供人交互的界面。Android的界面显示是一个三维空间,x,y轴控制需要展示的界面的大小,z轴控制界面显示的图层,这就存在界面显示优先级的说法了。

        下面简单的介绍下Window的优先级的设置方法:

private Window mWindow;

mWindow = getWindow();

mWindow.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); // 各种参数的优先级级别请参考下面Android源码


        adb shell进去执行以下指令可以看到Window所在layer:

        dumpsys -l  :列出所有可以查看的类型

        dumpsys window :列出所有正在运行的window相关参数,Surface: shown=true layer=161000 alpha=1.0 rect=(0.0,0.0) 1920.0 x 1.0参数有图层的大小

        dumpsys SurfaceFlinger :界面显示的层叠关系会必现的比较直观

        /**
         * Start of window types that represent normal application windows.
         */
        public static final int FIRST_APPLICATION_WINDOW = 1;
        
        /**
         * Window type: an application window that serves as the "base" window
         * of the overall application; all other application windows will
         * appear on top of it.
         * In multiuser systems shows only on the owning user's window.
         */
        public static final int TYPE_BASE_APPLICATION   = 1;
        
        /**
         * Window type: a normal application window.  The {@link #token} must be
         * an Activity token identifying who the window belongs to.
         * In multiuser systems shows only on the owning user's window.
         */
        public static final int TYPE_APPLICATION        = 2;
    
        /**
         * Window type: special application window that is displayed while the
         * application is starting.  Not for use by applications themselves;
         * this is used by the system to display something until the
         * application can show its own windows.
         * In multiuser systems shows on all users' windows.
         */
        public static final int TYPE_APPLICATION_STARTING = 3;
    
        /**
         * End of types of application windows.
         */
        public static final int LAST_APPLICATION_WINDOW = 99;
    
        /**
         * Start of types of sub-windows.  The {@link #token} of these windows
         * must be set to the window they are attached to.  These types of
         * windows are kept next to their attached window in Z-order, and their
         * coordinate space is relative to their attached window.
         */
        public static final int FIRST_SUB_WINDO
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值