title: [android Side By Side Camera
body: <p>Hi i want to show a live camera preview side by side on my Android Phone.
  Like this:</p>
  
  <p><a href="https://lh6.googleusercontent.com/-Ngo4tD4AvWY/U8JOHxxQ9KI/AAAAAAAACK8/NZjnw1Yqg8A/w384-h287/2.jpg" rel="nofollow">https://lh6.googleusercontent.com/-Ngo4tD4AvWY/U8JOHxxQ9KI/AAAAAAAACK8/NZjnw1Yqg8A/w384-h287/2.jpg</a></p>
  
  <p>It works if just the left half screen shows the live preview or just the right side,
  but if i want to show the left and the rigth side simultaneously i just get a black screen
  And i dont know why.</p>
  
  <p>Manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.test.normaltest.sbscameraview" &gt;
  
      &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
      &lt;uses-feature android:name="android.hardware.camera" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:screenOrientation="landscape"&gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>MainActivity</p>
  
  <pre><code>public class MainActivity extends Activity {
      private CameraView cameraView1;
      private CameraView cameraView2;
      private Camera mCamera1;
      private Camera mCamera2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mCamera1 = getCameraInstance();
          cameraView1 = new CameraView(this, mCamera1);
          cameraView2 = new CameraView(this, mCamera1);
  
          FrameLayout preview1 = (FrameLayout) findViewById(R.id.camera_preview1);
          preview1.addView(cameraView1);
  
          FrameLayout preview2 = (FrameLayout) findViewById(R.id.camera_preview2);
          preview2.addView(cameraView2);
      }
  
      /** A safe way to get an instance of the Camera object. */
      public static Camera getCameraInstance(){
          Camera c = null;
          try {
              c = Camera.open(); // attempt to get a Camera instance
          }
          catch (Exception e){
              Log.i("camera", "null");
          }
          return c; // returns null if camera is unavailable
      }
  }
  </code></pre>
  
  <p>CameraView</p>
  
  <pre><code>public class CameraView extends SurfaceView implements SurfaceHolder.Callback {
      private SurfaceHolder mHolder;
      private Camera mCamera;
  
  
      public CameraView(Context context, Camera camera) {
          super(context);
  
          mHolder = getHolder();
          mHolder.addCallback(this);
  
          mCamera = camera;
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
          try {
              mCamera.setPreviewDisplay(holder);
              mCamera.startPreview();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
          Log.i("CameraView", "surfaceChanged");
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
  
      }
  }
  </code></pre>