我创建了一个小部件,它是SurfaceView
的扩展名(非常类似于VideoView),我正在开发一项功能,可以在采取某些操作时在设备屏幕上完全展开视频。我查看onMeasure
的{{1}}函数并以这种方式重写:
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);
}
}
,以便视频在播放时得到拉伸,但我无法弄清楚如何强制刷新SurfaceView
。我尝试SurfaceView
,android.view.View.invalidate()
并直接使用不同的组合调用android.view.View.refreshDrawableState()
,但没有取得任何成功。有什么想法吗?
答案 0 :(得分:2)
无需代码以全屏模式播放视频
<?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>
答案 1 :(得分:1)
您可以像这样从活动中调用measure
的{{1}}方法:
SurfaceView
答案 2 :(得分:0)
Javanator是正确的答案。无需额外的代码。确保您的视频观看次序如下
<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">