16

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>
Jones
  • 307
  • 1
  • 4
  • 11

2 Answers2

38

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.

Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
3

My way is override the onMeasure method of VideoView

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
            getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
SDJSK
  • 1,292
  • 17
  • 24