title: Android Overlay 4/3 Image on Camera
body: <p>I have the following problem: I have an app with a camera and top of it and image as an Overlay. The Image is in 4/3 I get the optimal size for my screen and I draw the Image.
  The problem is that I don't see all the image when I try it. I have the image cutted on top and bottom of the screen. The thing is that if I take a picture then I see the photo perfect </p>
  
  <p>I'm using android sdk 8 and the camera is in landscape mode. In my Samsung galaxy S the overlay and the surfacepreview gives the same size 640:480. </p>
  
  <p>I have been playing for a while and I haven't found a solution yet.</p>
  
  <p>Here's the code.</p>
  
  <p>my xml: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/framecamera"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal"
      android:gravity="center"
      android:padding="0dip"
      android:layout_margin="0dip"
  &gt;
  &lt;FrameLayout
      android:id="@+id/surface"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="0dip"
      android:layout_margin="0dip"
  &gt;
  &lt;/FrameLayout&gt;
  &lt;ImageButton
      android:id="@+id/button_capture"
      android:contentDescription="@string/click"
      android:text="@string/click"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center|right"
      android:background="@drawable/camera"
      android:src="@drawable/camera"
  /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>the important parts of my code:</p>
  
  <pre><code>setContentView(R.layout.camera);
  
  //create an instance of Camera
  mcam = getCameraInstance();
  Camera.Parameters parameters=mcam.getParameters();
  size=getBestPreviewSize(parameters);//gets the 4/3 size
  
  horizontal = Bitmap.createScaledBitmap(horizontal, size.width, size.height, false);
  
  // Create our Preview view and set it as the content of our activity.
  mpreview = new CameraPreview(getBaseContext(), mcam);
  FrameLayout frame = (FrameLayout) findViewById(R.id.surface);
  SurfaceHolder mSurfaceHolder = mpreview.getHolder();
  mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
  //set our view to 4:3
  ViewGroup.LayoutParams params = frame.getLayoutParams();
  params.width = size.width;
  params.height = size.height;
  frame.setLayoutParams(params);
  
  //add the necessary margin to the view
  Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
  MarginLayoutParams ps=(MarginLayoutParams )frame.getLayoutParams();
  ps.topMargin = 0;
  ps.bottomMargin = 0;
  ps.leftMargin = (display.getWidth()-size.width)/2;//to center the overlay
  frame.setLayoutParams(ps);
  
  frame.addView(mpreview);
  
  over = new OverlayPreview(getBaseContext(),horizontal);//inside I draw the canvas
  frame.addView(over);
  </code></pre>
  
  <p>Any ideas would be greatly appreciated. I think the problem comes from the padding maybe or the xml but I don't know how to fix it. Thank you very much.</p>
  
  <p>p.d: Sorry for my english, not my first language.</p>