在SurfaceView扩展中将视频拉伸到全屏

SS.*_*SS. 5 android android-widget

我创建了一个小部件,它是SurfaceView(非常类似于VideoView)的扩展,我正在开发一项功能,可以在采取某些操作时在设备屏幕上完全展开视频.我查看了onMeasure函数VideoView并以这种方式重写它:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (mStretchVideo) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    } else {
        int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
        int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
        if (mVideoWidth > 0 && mVideoHeight > 0) {
            if (mVideoWidth * height > width * mVideoHeight) {
                height = width * mVideoHeight / mVideoWidth;
            } else if (mVideoWidth * height < width * mVideoHeight) {
                width = height * mVideoWidth / mVideoHeight;
            }
        }
        setMeasuredDimension(width, height);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我完全停止视频并再次开始播放,这似乎工作正常.现在我试图SurfaceView在设置拉伸标志后强制刷新它,以便视频在播放时被拉伸,但我无法弄清楚如何强制刷新SurfaceView.我尝试过android.view.View.invalidate(),直接用不同的组合android.view.View.refreshDrawableState()调用android.view.View.measure(int, int),但没有取得任何成功.有任何想法吗?

Jav*_*tor 2

无需代码即可全屏模式播放视频

在包含视频视图的 xml 上应用以下布局格式,它肯定会以全屏模式播放视频。因为它正在运行我的:)希望有帮助

 <?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/myvideoview"
             android:layout_width="fill_parent"
             android:layout_alignParentRight="true"
             android:layout_alignParentLeft="true"
             android:layout_alignParentTop="true"
             android:layout_alignParentBottom="true"
             android:layout_height="fill_parent">
    </VideoView>
 </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)