Class SurfaceViewWithAutoAR

java.lang.Object
android.view.View
android.view.SurfaceView
com.bambuser.broadcaster.SurfaceViewWithAutoAR
All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback

public class SurfaceViewWithAutoAR extends SurfaceView
A SurfaceView which adjusts its aspect ratio to fit the camera preview resolution. This fits nicely in a landscape oriented application and prevents stretching of the preview image received from the android camera. Make sure that this surface view can resize itself within the parent layout (use WRAP_CONTENT).
  • Constructor Details

    • SurfaceViewWithAutoAR

      public SurfaceViewWithAutoAR(Context context)
    • SurfaceViewWithAutoAR

      public SurfaceViewWithAutoAR(Context context, AttributeSet attrs)
    • SurfaceViewWithAutoAR

      public SurfaceViewWithAutoAR(Context context, AttributeSet attrs, int defStyle)
  • Method Details

    • setCropToParent

      public void setCropToParent(boolean crop)
      Sets whether the content of the view should be cropped to fit the parent layout, or shrunk (maintaining aspect ratio) to fit within the parent. The default is true.

      This can also be set via the cropToParent attribute via XML.

      Parameters:
      crop - whether to crop the content
    • cropToParent

      public boolean cropToParent()
      Check if the content of the view will be cropped or shrunk in order to fit the parent layout
      Returns:
      whether cropping is enabled
    • onMeasure

      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
      Overrides:
      onMeasure in class SurfaceView