English | Site Directory

Android - An Open Handset Alliance Project

android.view
public class

android.view.SurfaceView

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.view.SurfaceView

Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen

The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes.

Access to the underlying surface is provided via the SurfaceHolder interface, which can be retrieved by calling getHolder().

The Surface will be created for you while the SurfaceView's window is visible; you should implement surfaceCreated(SurfaceHolder) and surfaceDestroyed(SurfaceHolder) to discover when the Surface is created and destroyed as the window is shown and hidden.

One of the purposes of this class is to provide a surface in which a secondary thread can render in to the screen. If you are going to use it this way, you need to be aware of some threading semantics:

Known Direct Subclasses

Summary

XML Attributes inherited from class android.view.View
Constants inherited from class android.view.View
Fields inherited from class android.view.View

Public Constructors

          SurfaceView(Context context)
          SurfaceView(Context context, AttributeSet attrs, Map inflateParams)
          SurfaceView(Context context, AttributeSet attrs, Map inflateParams, int defStyle)

Public Methods

        void  draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
        boolean  gatherTransparentRegion(Region region)
This is used by the RootView to perform an optimization when the view hierarchy contains one or several SurfaceView.
        SurfaceHolder  getHolder()
Return the SurfaceHolder providing access and control over this SurfaceView's underlying surface.

Protected Methods

        void  onAttachedToWindow()
This is called when the view is attached to a window.
        void  onDetachedFromWindow()
This is called when the view is detached from a window.
        void  onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

        void  onScrollChanged(int l, int t, int oldl, int oldt)
This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents).
        void  onSizeChanged(int w, int h, int oldw, int oldh)
This is called during layout when the size of this view has changed.
        void  onWindowVisibilityChanged(int visibility)
Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE).
Methods inherited from class android.view.View