title: Android button on top of Camera preview
body: <p>I would like to add button on Android CameraPreview.
  Basically the hierarchy is following:</p>
  
  <ul>
  <li>Activity
  <ul>
  <li>ViewGroup<br>
  <ul>
  <li>SurfaceView</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>ViewGroup is wrapper around SurfaceView and centers CameraPreview.</p>
  
  <p>My current code in Activity.java is working (without the button):</p>
  
  <pre><code>mPreview = new Preview(this, mCamera, mJavaDetector);
  setContentView(mPreview);
  </code></pre>
  
  <p>Now I have created layout and want to place there a button.
  My layout main.xml looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/layout"&gt;
  
      &lt;LinearLayout
          android:id="@+id/preview"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="horizontal"
          android:visibility="visible"
          android:layout_alignParentTop="true"&gt;
      &lt;/LinearLayout&gt;
  
      &lt;Button android:text="Freeze" android:id="@+id/someButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"&gt;
      &lt;/Button&gt;      
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I have changed Activity.java:</p>
  
  <pre><code>setContentView(R.layout.main); 
  mPreview = new Preview(this, mCamera, mJavaDetector);
  
  LinearLayout ll = (LinearLayout)findViewById(R.id.preview);
  if(ll != null)
  {
      ll.addView(mPreview);
  }
  </code></pre>
  
  <p>And in Preview.java is created SurfaceView</p>
  
  <pre><code>mCameraPreview = new CameraPreview(context, camera, mJavaDetector);
  addView(mCameraPreview);
  </code></pre>
  
  <p>Now there is only the button on the screen but no CameraPreview. Could you tell me what am I doing wrong? Thanks.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>So let's say I have main.xml like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"&gt;
  
  
      &lt;fit.vutbr.faceswap.Preview
          android:id="@+id/preview"  
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"&gt;
  
          &lt;fit.vutbr.faceswap.CameraPreview
              android:id="@+id/camerapreview"  
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"&gt;
          &lt;/fit.vutbr.faceswap.CameraPreview&gt;
  
      &lt;/fit.vutbr.faceswap.Preview&gt;
  
  
      &lt;ImageButton
          android:id="@+id/imageButton1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@null"
          android:src="@drawable/switch_100px_white" /&gt;     
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Inside Activity.java:</p>
  
  <pre><code>setContentView(R.layout.main);
  mPreview = (Preview) findViewById(R.id.preview);
  mPreview.setPreview(this, mCamera, mJavaDetector);
  </code></pre>
  
  <p>Inside Preview.java:</p>
  
  <pre><code>mCameraPreview = (CameraPreview) findViewById(R.id.camerapreview);
  mCameraPreview.setCameraPreview(context, camera, mJavaDetector);
  </code></pre>
  
  <p>Where is the mistake in here?</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>Ok, it turned out that if I use main.xml like this I can see surfaceView:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;fit.vutbr.faceswap.Preview
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/preview"  
      android:layout_width="match_parent" 
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
     &lt;!--  &lt;ImageButton
              android:id="@+id/switch_camera_button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@null"
              android:src="@drawable/switch_100px_white" /&gt;    
      --&gt;        
      &lt;fit.vutbr.faceswap.CameraPreview
          android:id="@+id/camerapreview"  
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"&gt;
      &lt;/fit.vutbr.faceswap.CameraPreview&gt;
  
  
  &lt;/fit.vutbr.faceswap.Preview&gt;
  </code></pre>
  
  <p>Also I have found out that ViewGroup uses reverse order when adding new Views than other Layouts so the first added is the most on top.</p>
  
  <p>Right now if I uncomment ImageButton I get button over the whole screen and surfaceCreated() method from SurfaceView is never called. </p>