gpt4 book ai didi

Android VideoView 根据每个设备调整大小

转载 作者:行者123 更新时间:2023-11-29 23:05:58 28 4
gpt4 key购买 nike

我正在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com