title: Dynamic VideoView Height Based on Parent Width
body: <p>I'm trying to size a <code>VideoView</code> to the parent container width and then set the height to maintain a 4:3 aspect ratio.  I've seen some answers that recommend extending the <code>VideoView</code> class and overriding <code>onMeasure</code>, but I don't understand the parameters that I'm getting or how to use them:</p>
  
  <pre><code>package com.example;
  
  import android.content.Context;
  import android.util.AttributeSet;
  import android.util.Log;
  import android.widget.VideoView;
  
  public class MyVideoView extends VideoView {
  
      public MyVideoView(Context context) {
          super(context);
      }
  
      public MyVideoView (Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public MyVideoView (Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
      }
  
      @Override
      protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
          Log.i("MyVideoView", "width="+widthMeasureSpec);
          Log.i("MyVideoView", "height="+heightMeasureSpec);
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      }
  }
  </code></pre>
  
  <p>Result (on Nexus 7 tablet):</p>
  
  <pre><code>02-13 21:33:42.515: I/MyVideoView(12667): width=1073742463
  02-13 21:33:42.515: I/MyVideoView(12667): height=1073742303
  </code></pre>
  
  <p>I'm trying to achieve the following layout:</p>
  
  <p>Tablet (portrait):</p>
  
  <ul>
  <li>VideoView width - full or nearly full screen. </li>
  <li>VideoView height - maintain 4:3 aspect ratio given the width</li>
  <li>ListView - appears below the VideoView to select a video to play.</li>
  </ul>
  
  <p>Tablet (landscape):</p>
  
  <ul>
  <li>ListView - appears on the left of the screen, used to select a video to play.</li>
  <li>VideoView - appears on the right of the screen and should fill with remaining width and the set height to maintain the 4:3 aspect ratio.</li>
  </ul>