我有一些代码会在orientation changes:
时运行@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
setVideoSize();
_videoSurfaceView.changeCameraDisplaySize();
}
private void setVideoSize() {
//Get the dimensions of the video
int videoWidth = _videoSurfaceView.getCamera().getParameters().getPreferredPreviewSizeForVideo().width;
int videoHeight = _videoSurfaceView.getCamera().getParameters().getPreferredPreviewSizeForVideo().height;
float videoProportion = (float) videoWidth / (float) videoHeight;
// Get the width of the screen
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
float screenProportion = (float) screenWidth / (float) screenHeight;
// Get the SurfaceView layout parameters
android.view.ViewGroup.LayoutParams lp = _videoSurfaceView.getLayoutParams();
if (videoProportion > screenProportion) {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth / videoProportion);
} else {
lp.width = (int) (videoProportion * (float) screenHeight);
lp.height = screenHeight;
}
// Commit the layout parameters
_videoSurfaceView.setLayoutParams(lp);
}
在旋转发生时调用此方法,但我需要在完成旋转后运行setVideoSize()。有没有办法做到这一点?
答案 0 :(得分:0)
而是尝试在onResume()
中运行您的方法。当活动从暂停状态恢复时调用。
请注意,当您更改定向活动时,会重新创建活动,因此也会调用onResume()
。