original source : https://stackoverflow.com/a/4577249

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.

original source : https://stackoverflow.com/a/38496500

image

original source : https://stackoverflow.com/a/38496500

In one sentence, A Window is a rectangular area which has one view hierarchy. Colored rectangles in below image are windows.

image

As you can see, there can be multiple windows in one screen, and WindowManager manages them. 

According to Android Developer Documentation,

“Each activity is given a window in which to draw its user interface.”

and, Dianne Hackborn, who is a Android framework engineer, gave some definitions here. (1시간 분량) She said,

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

Also, I found some other info from Romain Guy’s presentation(You can watch his talk at San Francisco Android user group from here, and download full slides from here)

So, in a nutshell:

  • An Activity has a window (in which it draws its user interface),
  • a Window has a single Surface and a single view hierarchy attached to it,
  • a Surface include ViewGroup which holds views.

original source : https://youtu.be/vfnoT4TRmws

The Android Canvas, bitmap, paint에 관한 설명 1:00 부터 보면된다.

original source : https://stackoverflow.com/a/22442702

The Android WindowManager is a system service, which is responsible for managing the z-ordered list of windows, which windows are visible, and how they are laid out on screen. Among other things, it automatically performs window transitions and animations when opening or closing an app or rotating the screen.

Every activity has a Window that is used to display its content on the screen. When you call setContentView on an activity, it attaches that view to the activity’s default window. The default window fills the screen, so that your activity’s window hides any other activities – the WindowManager will display whichever window is on top. So normally you don’t need to worry about windows – you just create an activity and Android will do the rest for you.

But you need to interact with the WindowManager if you want to do something unusual like create floating windows that don’t fill the screen. If you want to create a floating window that is visible in front of other applications, you can’t use an activity because your activity will stop when another app comes to the foreground, and its window will be hidden or destroyed. Instead you need to display a window from a background service. For example:

iPhone – Get Position of UIView within entire UIWindow

iPhone – Get Position of UIView within entire UIWindow

Tinder Profile Grid – Mixing Code and Interface Builder (Ep 2)

my review point is 10/10

https://youtu.be/XCfVGYJAN0o   make window programmatically. navigation controller, collection view controller ( UICollectionViewFlowLayout )

https://youtu.be/XCfVGYJAN0o?t=4m40s   navigation title, title size, vertical bounce

https://youtu.be/XCfVGYJAN0o?t=6m10s   interface builder로 만든 요소를 코드로 불러와 사용하는 경우

https://youtu.be/XCfVGYJAN0o?t=6m50s   nib obj 만들기

https://youtu.be/XCfVGYJAN0o?t=7m33s   nib 화일을 collection view 에 연결하기 

https://youtu.be/XCfVGYJAN0o?t=8m40s   //MARK:-  사용

https://youtu.be/XCfVGYJAN0o?t=9m6s   

https://youtu.be/XCfVGYJAN0o?t=10m2s   header size 조정하기 ( UICollecitonViewDelegateFlowLayout )

https://youtu.be/XCfVGYJAN0o?t=15m5s   user defined runtime attributes  를 이용하는 방법

https://youtu.be/XCfVGYJAN0o?t=20m44s   round corner를 interface builder를 이용한 방법과 programmatically 조정하는 방법

https://youtu.be/XCfVGYJAN0o?t=22m27s   nib 화일로 만들어진 ui view에 programmatically 다른 요소를 추가하는 방법

Tinder Profile Grid – Mixing Code and Interface Builder (Ep 2)

my review point is 10/10

https://youtu.be/XCfVGYJAN0o   make window programmatically. navigation controller, collection view controller ( UICollectionViewFlowLayout )

https://youtu.be/XCfVGYJAN0o?t=4m40s   navigation title, title size, vertical bounce

https://youtu.be/XCfVGYJAN0o?t=6m10s   interface builder로 만든 요소를 코드로 불러와 사용하는 경우

https://youtu.be/XCfVGYJAN0o?t=6m50s   nib obj 만들기

https://youtu.be/XCfVGYJAN0o?t=7m33s   nib 화일을 collection view 에 연결하기 

https://youtu.be/XCfVGYJAN0o?t=8m40s   //MARK:-  사용

https://youtu.be/XCfVGYJAN0o?t=9m6s   

https://youtu.be/XCfVGYJAN0o?t=10m2s   header size 조정하기 ( UICollecitonViewDelegateFlowLayout )

https://youtu.be/XCfVGYJAN0o?t=15m5s   user defined runtime attributes  를 이용하는 방법

https://youtu.be/XCfVGYJAN0o?t=20m44s   round corner를 interface builder를 이용한 방법과 programmatically 조정하는 방법

https://youtu.be/XCfVGYJAN0o?t=22m27s   nib 화일로 만들어진 ui view에 programmatically 다른 요소를 추가하는 방법

About Windows and Views