Added in API level 1

SurfaceView


open class SurfaceView : View
kotlin.Any
   ↳ android.view.View
   ↳ 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.

The transparent region that makes the surface visible is based on the layout positions in the view hierarchy. If the post-layout transform properties are used to draw a sibling view on top of the SurfaceView, the view may not be properly composited with the surface.

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 SurfaceHolder.Callback.surfaceCreated and SurfaceHolder.Callback.surfaceDestroyed 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 into the screen. If you are going to use it this way, you need to be aware of some threading semantics:

Note: Starting in platform version android.os.Build.VERSION_CODES#N, SurfaceView's window position is updated synchronously with other View rendering. This means that translating and scaling a SurfaceView on screen will not cause rendering artifacts. Such artifacts may occur on previous versions of the platform when its window is positioned asynchronously.

Note: Starting in platform version android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE, SurfaceView will support arbitrary alpha blending. Prior platform versions ignored alpha values on the SurfaceView if they were between 0 and 1. If the SurfaceView is configured with Z-above, then the alpha is applied directly to the Surface. If the SurfaceView is configured with Z-below, then the alpha is applied to the hole punch directly. Note that when using Z-below, overlapping SurfaceViews may not blend properly as a consequence of not applying alpha to the surface content directly.

Summary

Inherited XML attributes
Constants
static Int

Default lifecycle of the Surface owned by this SurfaceView.

static Int

The Surface lifecycle is tied to SurfaceView attachment.

static Int

The Surface lifecycle is tied to SurfaceView visibility.

Inherited constants
Public constructors
SurfaceView(context: Context!)

SurfaceView(context: Context!, attrs: AttributeSet!)

SurfaceView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

SurfaceView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

Adds a transaction that would be applied synchronously with displaying the SurfaceView's next frame.

open Unit

Clears the SurfaceControlViewHost.SurfacePackage that was set on this SurfaceView.

open Unit
draw(canvas: Canvas)

open Boolean

open CharSequence!

open SurfaceControlViewHost.SurfacePackage?

Returns the SurfaceControlViewHost.SurfacePackage that was set on this SurfaceView.

open Int

Returns the composition order of the SurfaceView.

open SurfaceHolder!

Return the SurfaceHolder providing access and control over this SurfaceView's underlying surface.

open IBinder?

A token used for constructing SurfaceControlViewHost.

open Int

open SurfaceControl!

Return a SurfaceControl which can be used for parenting Surfaces to this SurfaceView.

open Boolean

open Unit
setAlpha(alpha: Float)

open Unit

Displays the view-hierarchy embedded within a SurfaceControlViewHost.SurfacePackage within this SurfaceView.

open Unit
setClipBounds(clipBounds: Rect!)

open Unit
setCompositionOrder(compositionOrder: Int)

Controls the composition order of the SurfaceView.

open Unit
setDesiredHdrHeadroom(desiredHeadroom: Float)

Sets the desired amount of HDR headroom to be used when HDR content is presented on this SurfaceView.

open Unit
setSecure(isSecure: Boolean)

Control whether the surface view's content should be treated as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.

open Unit
setSurfaceLifecycle(lifecycleStrategy: Int)

Controls the lifecycle of the Surface owned by this SurfaceView.

open Unit
setVisibility(visibility: Int)

open Unit
setZOrderMediaOverlay(isMediaOverlay: Boolean)

Control whether the surface view's surface is placed on top of another regular surface view in the window (but still behind the window itself).

open Unit

Control whether the surface view's surface is placed on top of its window.

Protected methods
open Unit

open Unit

open Unit

open Unit
onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?)

Called by the view system when the focus state of this view changes.

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Boolean
onSetAlpha(alpha: Int)

open Unit

Inherited functions