Android Videoview - 删除两侧的黑色空间

标签 android android-videoview

enter image description here

我将如何继续填充我的整个视频 View 以使黑框消失。我不想使用alignTop、bottom、left、right,因为当软键盘调整视频 View 时,对齐会阻止调整视频 View 。

<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>

编辑1:______________________________________________________

这就是当键盘出现时我使用对齐和重新调整时发生的情况我不想要这个

<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

最佳答案

我以前遇到过这个问题 - 没有简单、明显或开箱即用(android)的方法来做到这一点。

据我了解,您想要做的事情类似于ImageView上使用center_crop -正确吗?要实现此目的,您可以使用外部库或使用带有 TextureView 的编程解决方案(请参阅下面更详细的说明)

...

选项 A:使用外部库

有多个第三方库可用于此目的..

我以前没有用过这个,但如果我现在处于你的情况,我会选择这个。

用法:

构建.gradle

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

布局.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"/>

...或使用其他选项..

我以前用过这个。然而,它看到的最后一次更新是 4-6 年前,所以是的,不确定你是否想依赖它,而且开发人员表示不再支持该库。

用法:

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

然后

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();

...

选项 B:以编程方式解决问题

例如使用 TextureView

请参阅此处的这篇文章了解所有详细信息。基本上,您最终会计算必要的大小并操纵 View ......

Android VideoView crop_center

关于Android Videoview - 删除两侧的黑色空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58427146/

相关文章:

java.lang.RuntimeException : How do I solve this crash? 是什么原因造成的?

android - 耗时后的 Firebase 事件

android - 如何使用 VideoView Android 切换全屏

Android - VideoView 在 HDMI 模式下忽略 LayoutParams

java - 如何为新的警报对话框设置参数?

android - 在范围内时自动连接到配对的蓝牙设备

android - 在 Android 上播放 RTSP 流媒体

android - ScrollView 中的视频 View 问题

上一页和下一页可见的Android ViewPager?

android - 如何在框架布局或线性布局内创建全屏视频 View