gpt4 book ai didi

Android VideoView比例缩放

转载 作者:可可西里 更新时间:2023-11-01 18:46:52 29 4
gpt4 key购买 nike

在Android的VideoView中,有什么方法可以达到和ImageView.ScaleType.CENTER_CROP一样的效果吗?

也就是说,我希望我的 VideoView 播放视频,使其充满整个屏幕而不会失真。如果视频宽高比不完全适合屏幕,则应对其进行裁剪而不是扭曲。

以下解决方案将填满屏幕,但不保持视频的纵横比: https://stackoverflow.com/a/6927300/1068656

并且此解决方案保持视频的宽高比,但不会填满整个屏幕(视频会缩放直到较长的边碰到屏幕的边缘,从而在边上引入条形图): https://stackoverflow.com/a/4855315/1068656

最佳答案

虽然为时已晚,但它可能会帮助其他人寻找同样的问题。以下答案保持纵横比(videoProportion)。的额外部分videoview 被手机的 View 裁剪。

private void setDimension() {
// Adjust the size of the video
// so it fits on the screen
float videoProportion = getVideoProportion();
int screenWidth = getResources().getDisplayMetrics().widthPixels;
int screenHeight = getResources().getDisplayMetrics().heightPixels;
float screenProportion = (float) screenHeight / (float) screenWidth;
android.view.ViewGroup.LayoutParams lp = videoView.getLayoutParams();

if (videoProportion < screenProportion) {
lp.height= screenHeight;
lp.width = (int) ((float) screenHeight / videoProportion);
} else {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth * videoProportion);
}
videoView.setLayoutParams(lp);
}

// This method gets the proportion of the video that you want to display.
// I already know this ratio since my video is hardcoded, you can get the
// height and width of your video and appropriately generate the proportion
// as :height/width
private float getVideoProportion(){
return 1.5f;
}

关于Android VideoView比例缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11736311/

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