我正在使用扩展 GLSurfaceView 的视频视图,我希望在屏幕方向发生变化时调整它的大小。通常,当屏幕方向为横向时,将视图设置为全屏模式。我无法调整这个组件的大小,setLayoutParams 没有成功,我也尝试了 GLSurfaceView 的 surfaceChanged 方法,但没有成功。我可能错过了一些东西。
提前感谢您的回复。
我正在使用扩展 GLSurfaceView 的视频视图,我希望在屏幕方向发生变化时调整它的大小。通常,当屏幕方向为横向时,将视图设置为全屏模式。我无法调整这个组件的大小,setLayoutParams 没有成功,我也尝试了 GLSurfaceView 的 surfaceChanged 方法,但没有成功。我可能错过了一些东西。
提前感谢您的回复。
Without knowing more, I think the easiest way would be to utilize Android's default behavior of destroying and recreating your activity containing the GLSurfaceView
on orientation change. This would be done by specifying different layouts with the same name for portrait and landscape orientations and placing them in, for example, res/layout-port
and res/layout-land
folders.
Another possibility, since GLSurfaceView
can often contain a lot of state that you may not want to rebuild every time the orientation changes, is to use the android:configChanges
attribute in your Activity
specifying orientation
, and then resizing your GLSurfaceView
inside the onConfigurationChanged(Configuration)
method of your Activity
.