title: VideoView on top of SurfaceView
body: <p>I try to show a <code>VideoView</code> on top of a <code>SurfaceView</code>. But it isn't visible but reacts on clicks (MediaController appears and the sound plays). The video seems to be played behind the <code>SurfaceView</code> so I also tried to make use of <code>setZOrderMediaOverlay()</code> and/or <code>setZOrderOnTop()</code> but nothing changed</p>
  
  <p>When I go to the home screen I see the VideoView for a split second in the fading animation, so it is really there.</p>
  
  <p>I tried it with a xml layout and also completely programmatically but nothing works.</p>
  
  <p>Here is my activity:</p>
  
  <pre><code>public class VideoTest extends Activity {
      private RelativeLayout mLayout;
      private VideoView mVideo;
      private Handler mHandler;
      private FrameLayout mFrameLayout;
      private SurfaceView mSurfaceView;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          mFrameLayout = new FrameLayout(this);
          mFrameLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  
          mLayout = new RelativeLayout(this);
          mLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
          mVideo = new VideoView(this);
          mVideo.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
          mSurfaceView = new SurfaceView(this);
          mSurfaceView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  
          mSurfaceView.setZOrderMediaOverlay(false);
          mSurfaceView.setZOrderOnTop(false);
  
          mFrameLayout.addView(mSurfaceView);
          mLayout.addView(mVideo);
          mFrameLayout.addView(mLayout);
  
          setContentView(mFrameLayout);
  
          // with xml
  //        setContentView(R.layout.main);
  //        mFrameLayout = (FrameLayout) findViewById(R.id.activity_reader);
  //        mLayout = (RelativeLayout) findViewById(R.id.videoview);
  //        mVideo = (VideoView) findViewById(R.id.video_view);
  //        mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
  
          // Set the handler to me messaged from the threads
          mHandler = new Handler() {
              @Override
              public void handleMessage(Message msg) {
                  if (msg != null) {
                      mVideo.setMediaController(new MediaController(mVideo.getContext()));
                      mVideo.setVideoPath("/mnt/sdcard/myvideo.mp4");
                      if (mLayout.getVisibility() == View.VISIBLE) {
                          mLayout.setVisibility(View.GONE);
                      } else {
                          mLayout.setVisibility(View.VISIBLE);
                      }
  //                    mFrameLayout.bringChildToFront(mLayout);
  //                    mFrameLayout.bringChildToFront(mVideo);
  //                    mFrameLayout.requestLayout();
  //                    mFrameLayout.invalidate();
  //                    mFrameLayout.postInvalidate();
  //                    mVideo.requestFocus();
                  }
                  super.handleMessage(msg);
              }
          };
      }
  
      /** Inflate the menu */
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
              MenuInflater inflater = getMenuInflater();
              inflater.inflate(R.menu.activity_reader_menu, menu);
              return true;
      }
  
      /** Handle menu items events */
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case R.id.toggle_video:
                  new Thread() {
                      public void run() {
                          mHandler.sendEmptyMessage(0);
                      };
                  }.start();
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
      }
  }
  </code></pre>
  
  <p>My xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/activity_reader"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;SurfaceView android:id="@+id/surface_view"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
      &lt;RelativeLayout android:id="@+id/videoview"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:visibility="gone"&gt;
          &lt;VideoView android:id="@+id/video_view"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" /&gt;
      &lt;/RelativeLayout&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>One hint: As this is only a test to find out why it isn't working I tried to minimize the code from my real application where the visibility of the <code>VideoView</code> is controlled by a handler who get a message from the drawing thread of the <code>SurfaceView</code>. Thats the reason why I implemented a thread sending the message when the menu was used.</p>