31

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

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

=========

Android Window 的职责是什么?

这里有一些问题:

  • 它负责收集和分派输入吗?
  • 视图和窗口之间是什么关系?和DFB中表面和窗口的关系一样吗?
  • 活动和窗口之间有什么关系?每个Activity都会有一个窗口吗?
  • 是否可以从应用程序创建一个窗口?什么时候有必要?
  • Android是否支持多窗口?

编辑:添加更多问题:

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

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

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

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

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

  3. WindowManager 负责 Window 堆叠?这与 SurfaceFlinger 有什么关系?

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

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

  6. 何时调用 onDraw(Canvas)?如何和谁传递画布参数?

  7. 帆布有尺寸吗?Window 的表面是否总是全屏显示?

再次编辑:

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

  1. 每个 Activity 都会有一个 ViewRoot 和一个 Window 吗?
  2. 是否需要明确创建一个窗口?窗口的表面是否总是全屏?
  3. 状态栏会在另一个窗口中吗?
  4. 表面的尺寸是多少?会一直全屏吗?
4

4 回答 4

14

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?

于 2011-11-23T06:08:37.483 回答
4

感谢您提出所有这些问题。1) AFAIK 每个 Activity 至少有一个 ViewRoot,每个 ViewRoot 至少有一个窗口 2) 无需显式创建窗口,我认为它应该始终是全窗口 .. 虽然对此不确定 3) 是的,可以,我们可以在另一个窗口中放置状态栏 4)不是可以是窗口的一部分,并不总是覆盖全屏。

如果我在这里说错了,请纠正我的理解。

于 2011-11-22T08:05:16.297 回答
1

Android:Window、Surface、Canvas 和 Bitmap 概念

这是一个非常基本且简单的概念概述,说明了 Window、Surface、Canvas 和 Bitmap 之间的交互是如何发生的。
看看这个hackbod的答案,很好的解释。

于 2016-07-21T06:39:55.977 回答
0

对于这个问题

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

不同意@pierrotlefou,因为谷歌文档中的 SurfaceView 提供了一个专用的表面,而不是窗口。

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

于 2019-08-24T06:43:26.240 回答