The Developer Preview for Android 11 is now available; test it out and share your feedback.

PreviewView

public class PreviewView
extends FrameLayout

java.lang.Object
   ↳ 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 TextureView or SurfaceView to display the camera feed.

Summary

Nested classes

enum PreviewView.ImplementationMode

The implementation mode of a PreviewView

Specifies how the Preview surface will be implemented internally: Using a SurfaceView or a TextureView (which is the default)

 

Inherited constants

Inherited fields

Public constructors

PreviewView(Context context)
PreviewView(Context context, AttributeSet attrs)
PreviewView(Context context, AttributeSet attrs, int defStyleAttr)
PreviewView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

PreviewView.ImplementationMode getImplementationMode()

Returns the implementation mode of the PreviewView.

Preview.SurfaceProvider getPreviewSurfaceProvider()

Gets the Preview.SurfaceProvider to be used with Preview.setSurfaceProvider(Executor, Preview.SurfaceProvider).

void setImplementationMode(PreviewView.ImplementationMode implementationMode)

Specifies the PreviewView.ImplementationMode to use for the preview.

Protected methods

void onAttachedToWindow()
void onDetachedFromWindow()

Inherited methods

Public constructors

PreviewView

public PreviewView (Context context)

Parameters
context Context

PreviewView

public PreviewView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

PreviewView

public PreviewView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

PreviewView

public PreviewView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

getImplementationMode

public PreviewView.ImplementationMode getImplementationMode ()

Returns the implementation mode of the PreviewView.

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

getPreviewSurfaceProvider

public Preview.SurfaceProvider getPreviewSurfaceProvider ()

Gets the Preview.SurfaceProvider to be used with Preview.setSurfaceProvider(Executor, Preview.SurfaceProvider).

Returns
Preview.SurfaceProvider

setImplementationMode

public void setImplementationMode (PreviewView.ImplementationMode implementationMode)

Specifies the PreviewView.ImplementationMode to use for the preview.

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

Protected methods

onAttachedToWindow

protected void onAttachedToWindow ()

onDetachedFromWindow

protected void onDetachedFromWindow ()