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

Android GUI architecture - relation between Surface/view/window/canvas(Android GUI架构——Surface/view/window/canvas之间的关系)

本文介绍了Android GUI架构——Surface/view/window/canvas之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

UPDATE: After several days googling and experiments, I have found the answers for most of those dumb questions. See the answers I submitted.

=========

Android Window 的职责是什么?

What is the responsibility of Android Window?

这里有几个问题:

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

添加更多问题:

  1. Window、View、Canvas、Surface等各个类的职责是什么?它们之间是如何协作的?

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

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

How many windows usually an Activity have?

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

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

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

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

View负责focus/keyEvent/manager,而Cavus只负责绘图"操作.

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

WindowManager 负责窗口堆叠?这与 SurfaceFlinger 有什么关系?

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

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

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

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

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

什么时候会调用 onDraw(Canvas)?如何与谁传递了画布参数?

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

Canvas 有尺寸吗?Window 的表面会一直全屏吗?

Does Canvas has size? Will Window's surface always be full screen?

再次

看完 Romain Guy 提供的精彩演示后http://www.youtube.com/watch?v=duefsFTJXzc&feature=feedwll&list=WL ,几个问题解决了,再补充几个:)

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. 每个 Activity 是否都有一个 ViewRoot 和一个 Window?
  2. 是否需要显式创建一个窗口?以及窗口的表面是否总是全屏?
  3. 状态栏会在另一个窗口中吗?
  4. 表面的尺寸是多少?会一直全屏吗?

推荐答案

Window 是否负责收集和分派输入?

Is Window responsible for collecting and dispatching the input?

没有.ViewRoot 对此负责.

No. ViewRoot is responsible for this.

视图和窗口是什么关系?与DFB中表面和窗口的关系?

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?

是的,大多数时候.但是,SurfaceView 有自己的窗口.所以,如果一个 Activity 有一个 SurfaceView,它就会有多个 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?

没有必要.

Android 是否支持多窗口?

Does Android support multi-window?

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

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

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

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?

通常是一个.

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

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?

每个窗口都有一个表面,Surface 使用 Canvas 在表面上绘制.

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

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

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

是的.

6.WindowManager负责Window stacking?这与 SurfaceFlinger 有何关系?

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

不确定 WindowManager 的责任.(待办事项)

Not Sure of WindowManager's responsibility. (TODO)

SurfaceFlinger用于组成与不同Window/Activity关联的Surface.

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

7.View不拥有Surface,View包含的Window拥有?

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

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

View will draw on surface using Canvas. The window the view is attached to owns the surface.

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

This could be understood by implement a customize view, when you should override the onDraw(Canvas) method in your derived class.

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

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

是的.

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

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

onDraw() 将由 RootView 调用,并在调用 invalidate 时调用.canvas 参数是从 RootView 传递过来的.

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

10.Canvas有尺寸吗?Window 的表面是否总是全屏显示?

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

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

I cannot say for sure. But when I create a customize view, the size of the canvas got from onDraw(Canvas) is full screen.

但是,据我了解,出于性能考虑,窗口的 Surface 不应始终全屏.但这一假设尚未得到验证.例如,statusBar 窗口不应该是全屏的.

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.每个Activity会有一个ViewRoot,从而有一个Window吗?

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

是的.

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

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.状态栏会在另一个窗口吗?

3.Will status bar be in another Window?

是的.

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

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

这篇关于Android GUI架构——Surface/view/window/canvas之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android GUI架构——Surface/view/window/canvas之间的关系

基础教程推荐