2014-08-28 80 views
0

我有一些代码,运行时orientation changesAndroid上运行的方法是完全

@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

看看[这个](http://developer.android.com/reference/android/view/OrientationEventListener.html) – aProperFox 2014-08-28 16:48:02

+0

这有效。谢谢! – 2014-08-28 18:17:16

+0

很高兴听到它! – aProperFox 2014-08-28 19:13:39

回答

0

请尝试在onResume()中运行您的方法。从暂停状态恢复活动时调用。

请注意,当你改变你的方向活动重新创建因此onResume()也将被调用。

相关问题