title: Get full screen preview with Android camera2
body: <p>I'm building a custom camera using the new camera2 API. My code is based on the code sample provided by Google <a href="https://github.com/googlesamples/android-Camera2Video" rel="noreferrer">here</a>. </p>
  
  <p>I can't find a way to get the camera preview in full screen. In the code sample, they use ratio optimization to adapt to all screens but it's only taking around 3/4 of the screen's height.</p>
  
  <p>Here is my code of <code>AutoFitTextureView</code> :</p>
  
  <pre><code>public class AutoFitTextureView extends TextureView {
  
  private int mRatioWidth = 0;
  private int mRatioHeight = 0;
  
  public AutoFitTextureView(Context context) {
      this(context, null);
  }
  
  public AutoFitTextureView(Context context, AttributeSet attrs) {
      this(context, attrs, 0);
  }
  
  public AutoFitTextureView(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
  }
  
  /**
   * Sets the aspect ratio for this view. The size of the view will be measured based on the ratio
   * calculated from the parameters. Note that the actual sizes of parameters don't matter, that
   * is, calling setAspectRatio(2, 3) and setAspectRatio(4, 6) make the same result.
   *
   * @param width  Relative horizontal size
   * @param height Relative vertical size
   */
  public void setAspectRatio(int width, int height) {
      if (width &lt; 0 || height &lt; 0) {
          throw new IllegalArgumentException("Size cannot be negative.");
      }
      mRatioWidth = width;
      mRatioHeight = height;
      requestLayout();
  }
  
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      int width = MeasureSpec.getSize(widthMeasureSpec);
      int height = MeasureSpec.getSize(heightMeasureSpec);
  
      if (0 == mRatioWidth || 0 == mRatioHeight) {
          setMeasuredDimension(width, height);
      } else {
          if (width &lt; height * mRatioWidth / mRatioHeight) {
              setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
          } else {
              setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thank you very much for your help.</p>