views:

2688

answers:

3

When is it necessary, or better to use a SurfaceView instead of a View?

+3  A: 

The main difference is that SurfaceView can be drawn on by background theads but Views can't. They use more resources though so you don't want to use them unless you have to.

John Burton
+5  A: 

Views are all drawn on the same GUI thread which is also used for all user interaction.

So if you need to update GUI rapidly or if the rendering takes too much time and affects user experience then use SurfaceView.

niko
+7  A: 

A few things I've noted:

  • SurfaceViews contain a nice rendering mechanism that allows threads to update the surface's content without using a handler (good for animation).
  • Surfaceviews cannot be transparent, they can only appear behind other elements in the view hierarchy.
  • I've found that they are much faster for animation than rendering onto a View.

For more information (and a great usage example) refer to the LunarLander project in the SDK 's examples section.

Ralphleon