什么是 Android 装饰视图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23276847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is an Android DecorView?
提问by nmr
http://developer.android.com/reference/android/view/Window.html#getDecorView():
http://developer.android.com/reference/android/view/Window.html#getDecorView():
Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a window to the window manager.
检索顶级窗口装饰视图(包含标准窗口框架/装饰以及其中的客户端内容),可以将其作为窗口添加到窗口管理器中。
This is baffling. It is not clear what the standard "window frame/decorations" are. I'm at a loss as to what this is, exactly, and the documentation is terrible. Does it exist inside the application's window? Does it surround the application's window?
这令人费解。目前尚不清楚标准的“窗框/装饰品”是什么。我不知道这到底是什么,而且文档很糟糕。它是否存在于应用程序的窗口中?它是否围绕应用程序的窗口?
I have never seen an Android window with noticeable window decorations. And "which can be added as a window" implies that a decor view is a window, but that contradicts the class hierarchy (View
is not a subclass of Window
).
我从未见过带有明显窗口装饰的 Android 窗口。并且“可以添加为窗口”意味着装饰视图是一个窗口,但这与类层次结构相矛盾(View
不是 的子类Window
)。
So what's the deal? What exactly is the decor view?
那么有什么关系呢?究竟什么是装饰视图?
采纳答案by nKn
Seems that one of the places where it's best defined is in Romain Guy's Blog:
似乎最好定义的地方之一是在Romain Guy 的博客中:
The DecorView is the view that actually holds the window's background drawable. Calling getWindow().setBackgroundDrawable() from your Activity changes the background of the window by changing the DecorView‘s background drawable. As mentioned before, this setup is very specific to the current implementation of Android and can change in a future version or even on another device.
DecorView 是实际保存窗口背景可绘制的视图。从您的 Activity 调用 getWindow().setBackgroundDrawable() 会通过更改 DecorView 的可绘制背景来更改窗口的背景。如前所述,此设置非常特定于 Android 的当前实现,并且可以在未来版本中甚至在其他设备上更改。