VideoView内容调整大小(VideoView content resize)

1836 IT屋

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

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

但没有结果。


解决方案

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


  

公共类CustomVideoView扩展VideoView {

 保护INT _overrideWidth = 480;保护INT _overrideHeight = 360;公共CustomVideoView(上下文的背景下){
    超级(上下文);
}公共CustomVideoView(上下文的背景下,集合的AttributeSet){
    超(背景下,设定);
}公共无效resizeVideo(INT宽度,高度INT){
    _overrideHeight =高度;
    _overrideWidth =宽度;
    //不知道是否这样做是否有用,但安全
    getHolder()setFixedSize(宽度,高度)。
    // getHolder()setSizeFromLayout()。
    requestLayout();
    无效(); //非常重要的,这样onMeasure将触发}@覆盖
保护无效onMeasure(INT widthMeasureSpec,诠释heightMeasureSpec)
{
    setMeasuredDimension(_overrideWidth,_overrideHeight);
}

  
  

}


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

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

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);

but no results

解决方案

Make a custom video class like this:

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);
}

}

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.

本文地址:IT屋 » VideoView内容调整大小

相关文章: