I put an ImageView and a VideoView in a RelativeLayout.
The ImageView can be scaled to fill the whole layout by scaleType="fitXY"
. However, there is no similar scale attribute for the VideoView. By the way, I hide the video control by set setMediaController(null)
and only the video content displays. Is it possible to scale the VideoView without keep aspect ratio?
Here is the layout example.
<RelativeLayout
android:layout_width="280dp"
android:layout_height="200dp">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/image"
android:scaleType="fitXY" />
<VideoView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/video"
android:visibility="invisible"
android:layout_centerInParent="true" />
</RelativeLayout>
Try to put VideoView
inside RelativeLayout
and set below properties to show video in full screen :
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/video"
android:visibility="invisible"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"/>
Note : Please set visibility value based on your requirement.
My way is override the onMeasure method of VideoView
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With