我有一个简单的
Fragment
有一个ExoPlayer
PlayerView
。
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/black"
android:fitsSystemWindows="false">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/videoView"
app:surface_type="texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:controller_layout_id="@layout/custom_player_controls" />
</androidx.appcompat.widget.LinearLayoutCompat>
这是我播放超宽视频时的样子:
在左边,你可以看到相机裁剪的空间。如果我设置
LinearLayoutCompat
如果有其他颜色的背景,那么很明显
LinearLayoutCompat
占据了整个空间,甚至是切口所在的地方。那么为什么
播放器视图
占用那个空间?
我看不到任何设置
播放器视图
尺寸,我只是打电话
setPlayer()
然后把它传给我
ExoPlayer
例子
编辑:我又做了一次测试。我在
播放器视图
这种观点没有差距,但
播放器视图
在这个观点之前有一个空白。
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/black"
android:fitsSystemWindows="false">
<View
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@color/amber_200"
/>
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/videoView"
app:surface_type="texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:controller_layout_id="@layout/custom_player_controls" />
</androidx.appcompat.widget.LinearLayoutCompat>
它看起来是这样的:
编辑:玩了一会儿之后,我算出了屏幕和
播放器视图
都是一样的。所以我检查了页边空白,没有发现有什么不同,但我发现有一个填充。不知道这是否来自:
这样做可以解决我的问题,但我不确定这是否是一个好的解决方案:
binding.videoView.setPadding(0,0,0,0)