当前位置:   article > 正文

Android中WindowManger的层级分析_android windowmanager 指定层

android windowmanager 指定层

一. Window 分类

  •  应用 WindowApplicationWindow: 对应一个 Acitivity
  • 子 Window    SubWindow:不能单独存在,需要依附在特定的父 Window 中,比如常见的一些 Dialog 就是一个子 Window
  • 系统 Window SystemWindow:需要声明权限才能创建的 Window,比如 Toast 和系统状态栏都是系统 Window

二. Window层级

Window 是分层的,每个 Window 都有对应的 z-ordered,层级大的会覆盖在层级小的 Window 上面,这和 HTML 中的 z-index 概念是完全一致的。

在三种 Window 中,每一种Window的层级范围也是不同的,如下:

应用Window    1~99

子Window        1000~1999

系统Window    2000~2999

这些层级范围对应着 WindowManager.LayoutParams type 参数,如果想要 Window 位于所有 Window 的最顶层,那么采用较大的层级即可,很显然系统 Window 的层级是最大的,当我们采用系统层级时,需要声明权限。

(1)应用程序窗口:

  1. package android.view;
  2. public interface WindowManager
  3. /**
  4. * Start of window types that represent normal application windows.
  5. */
  6. public static final int FIRST_APPLICATION_WINDOW = 1;
  7. /**
  8. * Window type: an application window that serves as the "base" window
  9. * of the overall application; all other application windows will
  10. * appear on top of it.
  11. * In multiuser systems shows only on the owning user's window.
  12. */
  13. public static final int TYPE_BASE_APPLICATION = 1;
  14. /**
  15. * Window type: a normal application window. The {@link #token} must be
  16. * an Activity token identifying who the window belongs to.
  17. * In multiuser systems shows only on the owning user's window.
  18. */
  19. public static final int TYPE_APPLICATION = 2;
  20. /**
  21. * Window type: special application window that is displayed while the
  22. * application is starting. Not for use by applications themselves;
  23. * this is used by the system to display something until the
  24. * application can show its own windows.
  25. * In multiuser systems shows on all users' windows.
  26. */
  27. public static final int TYPE_APPLICATION_STARTING = 3;
  28. /**
  29. * Window type: a variation on TYPE_APPLICATION that ensures the window
  30. * manager will wait for this window to be drawn before the app is shown.
  31. * In multiuser systems shows only on the owning user's window.
  32. */
  33. public static final int TYPE_DRAWN_APPLICATION = 4;
  34. /**
  35. * End of types of application windows.
  36. */
  37. public static final int LAST_APPLICATION_WINDOW = 99;

 (2)子窗口:

  1. package android.view;
  2. public interface WindowManager
  3. /**
  4. * Start of types of sub-windows. The {@link #token} of these windows
  5. * must be set to the window they are attached to. These types of
  6. * windows are kept next to their attached window in Z-order, and their
  7. * coordinate space is relative to their attached window.
  8. */
  9. public static final int FIRST_SUB_WINDOW = 1000;
  10. /**
  11. * Window type: a panel on top of an application window. These windows
  12. * appear on top of their attached window.
  13. */
  14. public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW;
  15. /**
  16. * Window type: window for showing media (such as video). These windows
  17. * are displayed behind their attached window.
  18. */
  19. public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1;
  20. /**
  21. * Window type: a sub-panel on top of an application window. These
  22. * windows are displayed on top their attached window and any
  23. * {@link #TYPE_APPLICATION_PANEL} panels.
  24. */
  25. public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2;
  26. /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout
  27. * of the window happens as that of a top-level window, <em>not</em>
  28. * as a child of its container.
  29. */
  30. public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3;
  31. /**
  32. * Window type: window for showing overlays on top of media windows.
  33. * These windows are displayed between TYPE_APPLICATION_MEDIA and the
  34. * application window. They should be translucent to be useful. This
  35. * is a big ugly hack so:
  36. * @hide
  37. */
  38. @UnsupportedAppUsage
  39. public static final int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4;
  40. /**
  41. * Window type: a above sub-panel on top of an application window and it's
  42. * sub-panel windows. These windows are displayed on top of their attached window
  43. * and any {@link #TYPE_APPLICATION_SUB_PANEL} panels.
  44. * @hide
  45. */
  46. public static final int TYPE_APPLICATION_ABOVE_SUB_PANEL = FIRST_SUB_WINDOW + 5;
  47. /**
  48. * End of types of sub-windows.
  49. */
  50. public static final in
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/325870
推荐阅读
相关标签
  

闽ICP备14008679号