Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView how to scale as ImageView scale type fitXY?

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>
like image 271
Jones Avatar asked Nov 28 '14 03:11

Jones


2 Answers

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.

like image 56
Haresh Chhelana Avatar answered Sep 20 '22 17:09

Haresh Chhelana


My way is override the onMeasure method of VideoView

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
            getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
like image 21
SDJSK Avatar answered Sep 20 '22 17:09

SDJSK