【问题标题】:Android Videoview - Removing black space on sidesAndroid Videoview - 去除两侧的黑色空间
【发布时间】:2019-10-17 07:28:41
【问题描述】:

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

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

【问题讨论】:

    标签: android android-videoview


    【解决方案1】:

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

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

    ...

    选项 A:使用外部库

    有不止一个第三方库可用于此..

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

    用法:

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

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

    我以前用过这个。但是,它看到的最后一次更新是 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

    请在此处参阅此帖子以了解所有详细信息。基本上你最终会计算必要的大小并操纵视图......

    Android VideoView crop_center

    【讨论】:

    • 是的!我试图在视频上进行中心裁剪。非常感谢您发现问题并分享解决方案。
    • 不客气 =) 就像我说我以前去过那里,所以我感到你的痛苦.. :D 哈哈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多