PreviewView

open class PreviewView : FrameLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ androidx.camera.view.PreviewView

Custom View that displays camera feed for CameraX's Preview use case.

This class manages the Surface lifecycle, as well as the preview aspect ratio and orientation. Internally, it uses either a android.view.TextureView or android.view.SurfaceView to display the camera feed.

Summary

Nested classes

The implementation mode of a PreviewView

Public constructors

<init>(@NonNull context: Context)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int)

Public methods

open PreviewView.ImplementationMode

Returns the implementation mode of the PreviewView.

open Preview.PreviewSurfaceProvider

Gets the Preview.PreviewSurfaceProvider to be used with Preview#setPreviewSurfaceProvider(Executor, Preview.PreviewSurfaceProvider).

open Unit

Specifies the ImplementationMode to use for the preview.

Public constructors

<init>

PreviewView(@NonNull context: Context)

<init>

PreviewView(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?)

<init>

PreviewView(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?,
    defStyleAttr: Int)

<init>

PreviewView(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

getImplementationMode

@NonNull open fun getImplementationMode(): PreviewView.ImplementationMode

Returns the implementation mode of the PreviewView.

Return
PreviewView.ImplementationMode: SURFACE_VIEW if the PreviewView is internally using a android.view.SurfaceView to display the camera feed, or TEXTURE_VIEW if a android.view.TextureView is being used.

getPreviewSurfaceProvider

@NonNull open fun getPreviewSurfaceProvider(): Preview.PreviewSurfaceProvider

Gets the Preview.PreviewSurfaceProvider to be used with Preview#setPreviewSurfaceProvider(Executor, Preview.PreviewSurfaceProvider).

setImplementationMode

open fun setImplementationMode(@NonNull implementationMode: PreviewView.ImplementationMode): Unit

Specifies the ImplementationMode to use for the preview.

Parameters
implementationMode PreviewView.ImplementationMode: SURFACE_VIEW if a android.view.SurfaceView should be used to display the camera feed, or TEXTURE_VIEW to use a android.view.TextureView