2

enter image description here

How would I go upon filling my entire video view so that the black boxes go away. I don't want to use alignTop, bottom, left, right because when the softkeyboard adjust's the videoview, the aligns prevent the videoview from being adjusted.

<RelativeLayout
        android:id="@+id/fragment_video_video_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintHeight_percent=".33"
        app:layout_constraintWidth_default="percent"
        app:layout_constraintTop_toTopOf="parent"
        android:gravity="center">

        <VideoView
            android:id="@+id/fragment_video_video_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <ProgressBar
            android:id="@+id/video_progress_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

    </RelativeLayout>

Edit1:______________________________________________________

This is what happens when I use align and readjust when keyboard appears I DON'T WANT THIS

<VideoView
            android:id="@+id/fragment_video_video_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentLeft="true"/>

enter image description here

WHOATEMYNOODLES
  • 845
  • 9
  • 25

1 Answers1

2

I have come across this issue before - there is no easy, obvious or out of the box (android) way to do this.

From what I understand what you are trying to do i similar to using center_crop on an ImageView - correct? To achieve this you can either use an external library or use a programmatic solution with a TextureView (see more detailed explanations below)

...

OPTION A: Use an external library

there is more than one third party library available for this..

I havent used this one before, but I would go with this if I was in your situation right now.

Usage:

build.gradle

dependencies {
    compile 'com.yqritc:android-scalablevideoview:1.0.4'
}

layout.xml

<com.yqritc.scalablevideoview.ScalableVideoView
  android:id="@+id/video_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginBottom="100dp"
  app:scalableType="centerCrop"/>

... or use another option..

I have used this one before. However, the last update it has seen is 4-6 years ago, so yeah, not sure if you want to rely on that, plus the developer says the library is no longer supported.

Usage:

<com.dd.crop.TextureVideoView
        android:id="@+id/cropTextureView"
        android:layout_width="fill_parent"
        android:layout_height="100dp"/>

and then

TextureVideoView cropTextureView = (TextureVideoView) findViewById(R.id.cropTextureView);
cropTextureView.setScaleType(TextureVideoView.ScaleType.CENTER_CROP);
cropTextureView.setDataSource("http://www.w3schools.com/html/mov_bbb.mp4");
cropTextureView.play();

...

OPTION B: Solve the issue programatically

e.g. with a TextureView

Please refer to this post here for all the details. Basically you end up calculating the necessary size and manipulating the view…

Android VideoView crop_center

Community
  • 1
  • 1
Simon Mayrshofer
  • 1,264
  • 1
  • 11
  • 18