开发安卓的人对于一些概念的理解不够深刻,导致写代码很费力。现在就一些问题进行澄清。

Here are some definitions:

  • A Surface is an object holding pixels that are being composited to the screen. Every window you see on the screen (a dialog, your full-screen activity, the status bar) has its own surface that it draws in to, and Surface Flinger renders these to the final display in their correct Z-order. A surface typically has more than one buffer (usually two) to do double-buffered rendering: the application can be drawing its next UI state while the surface flinger is compositing the screen using the last buffer, without needing to wait for the application to finish drawing.

  • A window is basically like you think of a window on the desktop. It has a single Surface in which the contents of the window is rendered. An application interacts with the Window Manager to create windows; the Window Manager creates a Surface for each window and gives it to the application for drawing. The application can draw whatever it wants in the Surface; to the Window Manager it is just an opaque rectangle.

  • A View is an interactive UI element inside of a window. A window has a single view hierarchy attached to it, which provides all of the behavior of the window. Whenever the window needs to be redrawn (such as because a view has invalidated itself), this is done into the window's Surface. The Surface is locked, which returns a Canvas that can be used to draw into it. A draw traversal is done down the hierarchy, handing the Canvas down for each view to draw its part of the UI. Once done, the Surface is unlocked and posted so that the just drawn buffer is swapped to the foreground to then be composited to the screen by Surface Flinger.

  • A SurfaceView is a special implementation of View that also creates its own dedicated Surface for the application to directly draw into (outside of the normal view hierarchy, which otherwise must share the single Surface for the window). The way this works is simpler than you may expect -- all SurfaceView does is ask the window manager to create a new window, telling it to Z-order that window either immediately behind or in front of the SurfaceView's window, and positioning it to match where the SurfaceView appears in the containing window. If the surface is being placed behind the main window (in Z order), SurfaceView also fills its part of the main window with transparency so that the surface can be seen.

  • A Bitmap is just an interface to some pixel data. The pixels may be allocated by Bitmap itself when you are directly creating one, or it may be pointing to pixels it doesn't own such as what internally happens to hook a Canvas up to a Surface for drawing. (A Bitmap is created and pointed to the current drawing buffer of the Surface.)

Also please keep in mind that, as this implies, a SurfaceView is a pretty heavy-weight object. If you have multiple SurfaceViews in a particular UI, stop and think about whether this is really needed. If you have more than two, you almost certainly have too many.

高处看Surface,WIndow,View,SurfaceView相关推荐

  1. android surface windows,Android易混概念辨析之Surface,Window,View,SurfaceView,Bitmap

    本文来自stackoverflow上的一个回答,很适合那些对这些概念感觉明白又说不明白它们之间的区别与联系的Android开发者. Surface 一个Surface就是一个对象,该对象持有一群像素( ...

  2. Android之Surface/Window/View/SurfaceView区别

    Activity获得一块显存(Surface && FrameBuffer),然后在上面绘图(OpenGL && GPU),最后交给设备 去显示(Display设备). ...

  3. 可以在子线程绘画的View SurfaceView

    转载请注明出处:王亟亟的大牛之路 最近两天都没有写文章,一方面是自己在看书,一方面不知道写什么,本来昨天想写Glide或者RxAndroid的东西结果公司的"狗屎"网怎么都刷不好G ...

  4. View,SurfaceView,SurfaceHolder

    View:对于绘画来说,最重要的步骤是重载 onDraw方法并且修改画布Canvas. SurfaceView:1,You can control the format of this surface ...

  5. android surface用法,Android SurfaceView的基本使用

    一.为什么要SurfaceView 大多数情况下我们的自定义View都会选择去继承View或ViewGroup来实现,但是为什么系统还要为我们提供一个SurfaceView呢? 首先我们知道View类 ...

  6. Activity Window View WindowManager关系Touch事件分发机制

    http://www.cnblogs.com/linjzong/p/4191891.html https://www.cnblogs.com/kest/p/5141817.html https://b ...

  7. android.view.surface,Android SurfaceView 源码分析及使用

    概述 SurfaceView 是 Android 中一种比较特殊的视图(View),它跟平时时候的 TextView.Button 最大的区别是它跟它的视图容器并不是在同一个视图层上,它的 UI 显示 ...

  8. Android中的Android中的Surface和SurfaceView

    一.什么是Surface 简单的说Surface对应了一块屏幕缓冲区,每个window对应一个Surface,任何View都要画在Surface上.传统的view共享一块屏幕缓冲区,所有的绘制必须在U ...

  9. Surface、SurfaceView、SurfaceHolder及SurfaceHolder.Callback之间的关系

    转载请包含网址:http://blog.csdn.net/pathuang68/article/details/7351317 一.Surface Surface就是"表面"的意思 ...

最新文章

  1. sqlserver mysql 乱码_SQLServer数据库如何解决中文乱码问题?方法有哪些?
  2. 浅析基于双目视觉的自动驾驶技术
  3. 滴滴重磅发布:KDD2018大会187页人工智能+交通教程
  4. 【Webview相关问题】控制字符引发的惨案及Base64
  5. C# MongoDB简单增删改查使用
  6. Spring Boot filter
  7. Angular 依赖注入的一个常见错误 NullInjectorError, No provider for XXX
  8. 多普勒效应及多普勒频移的简单推导
  9. md5 java代码_JAVA简单实现MD5注册登录加密实例代码
  10. [读书笔记] 美的历程
  11. java 十亿数据去重_如何在有限的内存限制下实现数十亿级手机号码去重
  12. POJ 3250 Bad Hair Day - 单调队列
  13. 申作军海通机器人_青岛海通机器人系统有限公司
  14. vue el-menu多级菜单递归
  15. be [prove] a great boon to [for]
  16. 华为模拟器eNSP配置DHCP自动分配IP地址
  17. Volatility FAQ
  18. 关于华为和荣耀手机升级鸿蒙系统之后无法连接magicbook多屏协同的问题
  19. 常用 XML 解析技术
  20. 百度AI的2020:新基建铺路,硬实力出圈

热门文章

  1. java1.8 indexes_java1.8源码之ArrayList源码解读
  2. python取特定年份的数据_python,_怎样用python提取不同股票csv里特定时间段的数据,python - phpStudy...
  3. C++知识点24——使用C++标准库(顺序容器deque的初始化,赋值,访问,添加,删除,交换与迭代器失效)
  4. win7 计算机右键没有属性,系统之家windows7旗舰版计算机上右键菜单没有属性怎么办?...
  5. python简易爬虫课程设计_python实现简单爬虫功能的示例
  6. 软件体系架构阅读笔记一
  7. 《effective java》类和对象
  8. Linux IO多路复用之epoll网络编程(含源码)
  9. 【Unity/Kinect】获取预制的手势信息KinectInterop.HandState
  10. excel两个下拉框相互关联