我正在 Android 视频 View 中播放视频。问题是视频未根据设备比例调整大小。在大设备上它拉伸(stretch)或在小设备上它是 skeqzes。有没有办法像中心裁剪一样保持比例和填充全宽。
我检查了以下答案:
Resize video to fit the VideoView
Android VideoView orientation change with buffered video
但没有任何作用。
我的代码:
mBinding.videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
mBinding.placeholder.setVisibility(View.GONE);
return true;
}
return false;
}
});
mp.setLooping(true);
}
});
XML:
<VideoView
android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
最佳答案
将整个 xml 布局包装到 RelativeLayout
中。然后修改你的 VideoView
标签如下 -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView android:id="@+id/videoView"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
</RelativeLayout>
关于Android VideoView 根据每个设备调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56555686/