title: How can I set camera preview size to squared aspect ratio in a squared SurfaceView (like Instagram)
body: <p>I'm trying to develop my own camera activity, but I have a problem that I'm not unable to solve...</p>
  
  <p>What I want, is something very similiar to instagram photo frame, and this is what I get:</p>
  
  <p><img src="https://i.stack.imgur.com/L5dYk.png" alt="My image"></p>
  
  <p>When I should get something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/pizOR.png" alt="Instagram image"></p>
  
  <p>and...</p>
  
  <p><img src="https://i.stack.imgur.com/oa9jh.png" alt="My second image"></p>
  
  <p>when I should get something like:</p>
  
  <p><img src="https://i.stack.imgur.com/Fez7f.png" alt="Instagram 2"></p>
  
  <p>I think I'm maanaging the SurfaceView and Camera preview well, only using</p>
  
  <pre><code>Camera.Parameters parameters = camera.getParameters();
  camera.setDisplayOrientation(90);
  </code></pre>
  
  <p>and Custom SurfaceView:</p>
  
  <pre><code>public class SquaredSurfaceView extends SurfaceView {
  
  private int width;
  private int height;
  
  public SquaredSurfaceView(Context context) {
      super(context);
  }
  
  public SquaredSurfaceView(Context context, AttributeSet attrs) {
      super(context, attrs);
  }
  
  public SquaredSurfaceView(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
  }
  
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      width = MeasureSpec.getSize(widthMeasureSpec);
      height = width;
      setMeasuredDimension(width, width);
  }
  
  public int getViewWidth() {
      return width;
  }
  
  public int getViewHeight() {
      return height;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>What I'm doing wrong??  :-(</p>