Note that there are some explanatory texts on larger screens.

plurals
  1. POVideoView to match parent height and keep aspect ratio
    text
    copied!<p>I have a VideoView which is set up like this:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/player" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;VideoView android:id="@+id/video" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_centerInParent="true" android:layout_centerVertical="true" /&gt; &lt;ProgressBar android:id="@+id/loader" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>But the VideoView matches the width of the parent container, and then the height is set according to the aspect ratio of the loaded movie.<br/> I would like to do just the opposite, I want the VideoView to match the height of the parent while keeping the aspect ratio intact, the video will be clipped on the sides.</p> <p>I managed to stretch the VideoView to fill the parent but then the aspect ratio is not kept.</p> <p>Another thing is, I'm adding MediaController to the VideoView like this:</p> <pre><code>MediaController controllers = new MediaController(this) { @Override public void hide() { if (state != State.Hidden) { this.show(); } else { super.hide(); } } }; controllers.setAnchorView(videoView); videoView.setMediaController(controllers); videoView.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { controllers.show(); } }); </code></pre> <p>This works great, and the controllers always stay on, but the height of the controllers is not being taken into account when calculating where to place the video (since it's vertically centered).</p> <p>My two questions then are:</p> <ol> <li>How do I make the VideoView match the height of the parent yet keep the aspect ratio?</li> <li>How do I make the VideoView take into account the height of it's controllers?</li> </ol> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload