Android GUI架构-Surface/view/window/canvas之间的关系
=========================
更新:经过几天的谷歌搜索和 通过实验,我找到了大多数愚蠢问题的答案。查看我提交的答案。
=========
Android Window 的职责是什么?
这里有一些问题:
- 它是否负责收集和发送输入?
- 视图和窗口之间有什么关系?和DFB中surface和window的关系一样吗?
- Activity 和窗口之间有什么关系?每个Activity都会有一个窗口吗?
- 是否可以从应用程序创建一个窗口?什么时候有必要?
- 安卓支持多窗口吗?
编辑:添加更多问题:
各种类的职责是什么,例如 Window、View、Canvas、Surface 以及它们如何相互协作?
一个 Activity 通常有多少个窗口?
3.一个Activity中的所有视图都会附加到Window上吗? 附加是什么意思?
每个窗户都有表面吗?每个画布都有表面吗?
View 负责 focus/keyEvent/ manager,而 Cavus 只负责“绘图”操作。
WindowManager负责窗口堆叠?这和SurfaceFlinger有什么关系?
View 不拥有 Surface ,即视图包含的 Window ?
View 使用通过调用 surface.lockCanvas() 获得的画布绘制自身。
什么时候onDraw(Canvas)会被调用?如何&谁传递canvas参数?
画布有尺寸吗? Window 的表面会一直全屏吗?
再次编辑:
观看 Romain Guy http://www.youtube 提供的精彩演示后。 com/watch?v=duefsFTJXzc&feature=feedwll&list=WL ,解决了几个问题并添加了更多:)
- 每个 Activity 都会有一个 ViewRoot因此只有一个窗口?
- 是否需要显式创建一个窗口?窗口表面是否始终全屏?
- 状态栏会在另一个窗口中吗?
- 表面的尺寸是多少?会一直全屏吗?
=========================
UPDATE: After several days googling and experiments, I have found the answers for most of those dumb questions. See the answers I submitted.
=========
What is the responsibility of Android Window?
Here are some questions:
- Is it responsible for collecting and dispatching the input?
- What is the relationship between the view and window? Same as the relationship between surface and window in DFB?
- What is the relationship between an activity and window? Will each Activity has a window?
- Is it possible to create a window from application ? And when it is necessary?
- Does Android support multi-window?
EDIT: Add more questions:
What is responsibilities of various class , such as Window, View, Canvas, Surface and how they collaborate with each other?
How many windows usually an Activity have?
3.Will all the views in one Activity will be attached to Window?
What does attach mean?
Every window have surface? Every Canvas has surface?
View is responsible for focus/keyEvent/ manager, while Cavus is only responsible for "drawing" operation.
WindowManager is responsible for Window stacking? How that is related with SurfaceFlinger?
View doesn't own a Surface , the Window the view contained owns?
The View draw itself using canvas got by calling surface.lockCanvas().
When onDraw(Canvas) will be called? How & who pass the canvas parameters?
Does Canvas has size? Will Window's surface always be full screen?
EDIT again:
After watching this wonderful presentatin provided by Romain Guy http://www.youtube.com/watch?v=duefsFTJXzc&feature=feedwll&list=WL , several questions are resolved and add several more :)
- Will every Activity has one ViewRoot and thus one Window?
- Is there any need to create a window explictly? and Will the surface for the window always be full screen?
- Will status bar be in another Window?
- What is the size of the surface? Will that always be full screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不。ViewRoot 对此负责。
?
是的,大多数时候。然而,SurfaceView 有自己的窗口。因此,如果一个 Activity 有一个 SurfaceView,那么它就会有多个 Window。
没有必要。
当然。使用HierachyView你可以清楚地看到系统中存在多个Window。
通常是一个。
每个 Window 都有一个 Surface,
Surface
使用Canvas
在 Surface 上绘图。是的。
不确定 WindowManager 的责任。 (TODO)
SurfaceFlinger 用于组合与不同 Window/Activity 关联的 Surface。
视图将使用 Canvas 在表面上绘制。视图所附加到的窗口拥有该表面。
当您应该重写派生类中的 onDraw(Canvas) 方法时,可以通过实现自定义视图来理解这一点。
是的。
onDraw()
将由RootView
以及调用 invalidate 时调用。 canvas 参数是从 RootView 传递的。我不能肯定地说。但是当我创建自定义视图时,从 onDraw(Canvas) 获取的画布大小是全屏的。
然而,根据我的理解,出于性能考虑,窗口的Surface不应该总是全屏。但这一假设尚未得到验证。例如,statusBar 窗口不应该是全屏的。
是的。
本身不需要显式创建窗口。
是的。
No. ViewRoot is responsible for this.
?
Yes, most of the time. However, a SurfaceView has its own window. So, if an Activity has a SurfaceView it will have more than one Window.
Not necessary.
Sure. Using HierachyView you can clearly see that there is more than one Window exists in the system.
Usually one.
Every Window has a surface and
Surface
usesCanvas
to draw on the surface.YES.
Not Sure of WindowManager's responsibility. (TODO)
SurfaceFlinger
is used to compose the Surface that is associated with different Window/Activity.View will draw on surface using Canvas. The window the view is attached to owns the surface.
This could be understood by implement a customize view, when you should override the
onDraw(Canvas)
method in your derived class.YES.
onDraw()
will be called by theRootView
and when invalidate is called. The canvas parameter is passed from the RootView.I cannot say for sure. But when I create a customize view, the size of the canvas got from onDraw(Canvas) is full screen.
However, in my understanding, for performance sake, the Surface for the window should not always be full screen. But this assumption has not been verified. For example, the statusBar window should not be full screen.
YES.
No need to create the Window explicitly per se.
YES.
感谢您提出所有这些问题。
1) AFAIK 每个 Activity 至少有一个 ViewRoot 并且每个 ViewRoot 至少有一个窗口
2)不需要显式创建窗口,我认为它应该始终是完整的窗口..尽管不确定这一点
3)是的,我们可以将状态栏放在另一个窗口中
4) 不能是窗口的一部分,并不总是覆盖全屏。
如果我在这里说错了什么,请纠正我的理解。
Appreciating that you asked all those questions.
1) AFAIK every Activity has alteast one ViewRoot and every ViewRoot has atleast one window
2) There is no need to create window explicitly and I think it should always be full window .. although not sure about this
3) Yes it can be, we can place status bar in another windows
4) Not is can be part of window, not always covers full screen.
Please correct my understanding if I stated anything wrong here.
这是关于 Window、Surface、Canvas 和 Bitmap 之间如何进行交互的非常基本且简单的概念性概述。
看看这个答案由hackbod ,很好的解释。
Here is a very basic and simple conceptual overview of how interaction happens among the Window, Surface, Canvas, and Bitmap.
Look at this answer by hackbod, great explanation.
对于这个问题
不同意@pierrotlefou,因为在google doc SurfaceView 提供了专用表面,而不是比窗口。
for the question
disagree with @pierrotlefou ,cause in google doc SurfaceView provides a dedicated surface, rather than Window.