Android GUI架构-Surface/view/window/canvas之间的关系

发布于 2024-12-10 11:29:10 字数 1353 浏览 0 评论 0原文

=========================

更新:经过几天的谷歌搜索和 通过实验,我找到了大多数愚蠢问题的答案。查看我提交的答案。

=========

Android Window 的职责是什么?

这里有一些问题:

  • 它是否负责收集和发送输入?
  • 视图和窗口之间有什么关系?和DFB中surface和window的关系一样吗?
  • Activity 和窗口之间有什么关系?每个Activity都会有一个窗口吗?
  • 是否可以从应用程序创建一个窗口?什么时候有必要?
  • 安卓支持多窗口吗?

编辑:添加更多问题:

  1. 各种类的职责是什么,例如 Window、View、Canvas、Surface 以及它们如何相互协作?

  2. 一个 Activity 通常有多少个窗口?

3.一个Activity中的所有视图都会附加到Window上吗? 附加是什么意思?

  1. 每个窗户都有表面吗?每个画布都有表面吗?

  2. View 负责 focus/keyEvent/ manager,而 Cavus 只负责“绘图”操作。

  3. WindowManager负责窗口堆叠?这和SurfaceFlinger有什么关系?

  4. View 不拥有 Surface ,即视图包含的 Window ?

  5. View 使用通过调用 surface.lockCanvas() 获得的画布绘制自身。

  6. 什么时候onDraw(Canvas)会被调用?如何&谁传递canvas参数?

  7. 画布有尺寸吗? Window 的表面会一直全屏吗?

再次编辑:

观看 Romain Guy http://www.youtube 提供的精彩演示后。 com/watch?v=duefsFTJXzc&feature=feedwll&list=WL ,解决了几个问题并添加了更多:)

  1. 每个 Activity 都会有一个 ViewRoot因此只有一个窗口?
  2. 是否需要显式创建一个窗口?窗口表面是否始终全屏?
  3. 状态栏会在另一个窗口中吗?
  4. 表面的尺寸是多少?会一直全屏吗?

=========================

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:

  1. What is responsibilities of various class , such as Window, View, Canvas, Surface and how they collaborate with each other?

  2. How many windows usually an Activity have?

3.Will all the views in one Activity will be attached to Window?
What does attach mean?

  1. Every window have surface? Every Canvas has surface?

  2. View is responsible for focus/keyEvent/ manager, while Cavus is only responsible for "drawing" operation.

  3. WindowManager is responsible for Window stacking? How that is related with SurfaceFlinger?

  4. View doesn't own a Surface , the Window the view contained owns?

  5. The View draw itself using canvas got by calling surface.lockCanvas().

  6. When onDraw(Canvas) will be called? How & who pass the canvas parameters?

  7. 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 :)

  1. Will every Activity has one ViewRoot and thus one Window?
  2. Is there any need to create a window explictly? and Will the surface for the window always be full screen?
  3. Will status bar be in another Window?
  4. What is the size of the surface? Will that always be full screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

温柔少女心 2024-12-17 11:29:10

Window 负责收集和分派输入吗?

不。ViewRoot 对此负责。

视图和窗口之间有什么关系?与
DFB中曲面和窗口之间的关系?

activity和window之间有什么关系?每个 Activity 都会有一个窗口吗?

是的,大多数时候。然而,SurfaceView 有自己的窗口。因此,如果一个 Activity 有一个 SurfaceView,那么它就会有多个 Window。

是否可以从应用程序创建窗口?什么时候有必要?

没有必要。

Android支持多窗口吗?

当然。使用HierachyView你可以清楚地看到系统中存在多个Window。

1.WindowViewCanvasSurface等各个类的职责是什么,以及他们如何相互协作?
2.一个Activity通常有多少个窗口?

通常是一个。

3.一个Activity中的所有视图都会附加到一个窗口吗?附加是什么意思?
4.每个窗户都有表面吗?每块画布都有表面吗?

每个 Window 都有一个 Surface,Surface 使用 Canvas 在 Surface 上绘图。

5.View负责管理焦点/按键事件,而Canvas只负责“绘图”操作?

是的。

6.WindowManager负责窗口堆叠?这与 SurfaceFlinger 有何关系?

不确定 WindowManager 的责任。 (TODO)

SurfaceFlinger 用于组合与不同 Window/Activity 关联的 Surface。

7.View不拥有Surface,而是视图所包含的Window?

视图将使用 Canvas 在表面上绘制。视图所附加到的窗口拥有该表面。

当您应该重写派生类中的 onDraw(Canvas) 方法时,可以通过实现自定义视图来理解这一点。

8.View使用调用surface.lockCanvas()得到的canvas来绘制自己?

是的。

9.onDraw(Canvas)何时、如何调用,canvas参数由谁传递?

onDraw() 将由 RootView 以及调用 invalidate 时调用。 canvas 参数是从 RootView 传递的。

10.Canvas有尺寸吗?窗口表面总是全屏吗?

我不能肯定地说。但是当我创建自定义视图时,从 onDraw(Canvas) 获取的画布大小是全屏的。

然而,根据我的理解,出于性能考虑,窗口的Surface不应该总是全屏。但这一假设尚未得到验证。例如,statusBar 窗口不应该是全屏的。

1.每个Activity都会有一个ViewRoot,从而有一个Window吗?

是的。

2.是否需要显式创建窗口?窗口表面是否始终全屏?

本身不需要显式创建窗口。

3.状态栏会在另一个窗口吗?

是的。

4.表面的尺寸是多少?会一直全屏吗?

Is Window responsible for collecting and dispatching the input?

No. ViewRoot is responsible for this.

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 have a window?

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.

Is it possible to create a window from application? And when it is necessary?

Not necessary.

Does Android support multi-window?

Sure. Using HierachyView you can clearly see that there is more than one Window exists in the system.

1.What are the responsibilities of various classes, such as Window, View, Canvas, Surface, and how do they collaborate with each other?
2.How many windows usually an Activity have?

Usually one.

3.Will all the views in one Activity will be attached to a window? What does attach mean?
4.Does every window have a surface? Does every canvas have a surface?

Every Window has a surface and Surface uses Canvas to draw on the surface.

5.View is responsible for managing focus/key events, while Canvas is only responsible for "drawing" operation?

YES.

6.WindowManager is responsible for Window stacking? How does that relate to SurfaceFlinger?

Not Sure of WindowManager's responsibility. (TODO)

SurfaceFlinger is used to compose the Surface that is associated with different Window/Activity.

7.View doesn't own a Surface, the Window the view contained owns?

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.

8.The View draws itself using canvas got by calling surface.lockCanvas()?

YES.

9.When and how is onDraw(Canvas) called, and who passes the canvas parameters?

onDraw() will be called by the RootView and when invalidate is called. The canvas parameter is passed from the RootView.

10.Does Canvas have a size? Will a Window's surface always be full screen?

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.

1.Will every Activity have one ViewRoot and thus one Window?

YES.

2.Is there any need to create a window explicitly? Will the surface for the window always be full screen?

No need to create the Window explicitly per se.

3.Will status bar be in another Window?

YES.

4.What is the size of the surface? Will that always be full screen?

榕城若虚 2024-12-17 11:29:10

感谢您提出所有这些问题。
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.

指尖微凉心微凉 2024-12-17 11:29:10

Android: Window、Surface、Canvas 和 Bitmap 概念

这是关于 Window、Surface、Canvas 和 Bitmap 之间如何进行交互的非常基本且简单的概念性概述。
看看这个答案hackbod ,很好的解释。

Android: Window, Surface, Canvas, and Bitmap concept

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.

油焖大侠 2024-12-17 11:29:10

对于这个问题

activity和window之间有什么关系?每个Activity都会有一个窗口吗?

不同意@pierrotlefou,因为在google doc SurfaceView 提供了专用表面,而不是比窗口。

表面是 Z 排序的,因此它位于持有 SurfaceView 的窗口后面; SurfaceView 在其窗口中打一个孔以允许显示其表面。

for the question

What is the relationship between an activity and window? Will each Activity has a window?

disagree with @pierrotlefou ,cause in google doc SurfaceView provides a dedicated surface, rather than Window.

The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文