VideoView内容调整大小 [英] VideoView content resize

查看:2007
本文介绍了VideoView内容调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被设置为填补父母和正常工作与全尺寸的影片VideoView,我发现很难找到一个解决方案时,视频尺寸为4:3或更小的它不断向左我的看法,而在同一应用程序的IOS显示是它在全屏幕。
我们可以调整视频和那的一个视频显示相同的大小表现呢?或者可以VideoView内容的调整?
我试过

I have a VideoView which is set to fill parent and works fine with full size videos ,I am finding it difficult to find a solution when video size is 4:3 or smaller it keeps to left of my view whereas same application in ios display's it in full screen. Can we resize the video and show it with same size of that of a Video View?or can content of VideoView resized? I tried

view.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);

但没有结果。

推荐答案

请自定义视频类是这样的:

Make a custom video class like this:

公共类CustomVideoView扩展VideoView {

public class CustomVideoView extends VideoView {

protected int _overrideWidth = 480;

protected int _overrideHeight = 360;

public CustomVideoView(Context context) {
    super(context);
}

public CustomVideoView(Context context, AttributeSet set) {
    super(context, set);
}

public void resizeVideo(int width, int height) {
    _overrideHeight = height;
    _overrideWidth = width;
    // not sure whether it is useful or not but safe to do so
    getHolder().setFixedSize(width, height);
    //getHolder().setSizeFromLayout();
    requestLayout();
    invalidate(); // very important, so that onMeasure will be triggered

}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    setMeasuredDimension(_overrideWidth, _overrideHeight);
}


  
  

}

}

在你的类使用 resizeVideo 方法与屏幕宽度和高度的参数。

In your class use the resizeVideo method with the screen width and height as parameters.

您考虑所有依赖于电影比和屏幕比例。如果它们是相同的,比视频全屏显示,但是当它们是不同的,则视频被调节上宽度/高度

Take in account that all depends on the movie ratio and the screen ratio. If they are the same, than the video is displayed full screen, but when they are different, the video is adjusted on width/height.

这篇关于VideoView内容调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆