Android:旋转显示会导致相机预览变黑

Android:旋转显示会导致相机预览变黑,android,android-camera,surfaceview,Android,Android Camera,Surfaceview,我有一个代码,用于在方向改变时旋转和缩放SurfaceView。我遇到的问题是,当我旋转显示器时this.setRotation(*degrees*)预览将变为黑色。我不确定为什么会这样 public class VideoSurfaceView extends SurfaceView implements SurfaceHolder.Callback{ @Override public void surfaceChanged(SurfaceHolder surfaceHold

我有一个代码,用于在方向改变时旋转和缩放
SurfaceView
。我遇到的问题是,当我旋转显示器时
this.setRotation(*degrees*)预览将变为黑色。我不确定为什么会这样

public class VideoSurfaceView extends SurfaceView implements SurfaceHolder.Callback{

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {

        int videoWidth = this.getCamera().getParameters().getPreferredPreviewSizeForVideo().width;
        int videoHeight = this.getCamera().getParameters().getPreferredPreviewSizeForVideo().height;

        float videoProportion = (float) videoWidth / (float) videoHeight;

        WindowManager windowManager = (WindowManager)_appContext.getSystemService(Context.WINDOW_SERVICE);
        // Get the width of the screen
        int screenWidth = windowManager.getDefaultDisplay().getWidth();
        int screenHeight = windowManager.getDefaultDisplay().getHeight();
        float screenProportion = (float) screenWidth / (float) screenHeight;

        // Get the SurfaceView layout parameters
        android.view.ViewGroup.LayoutParams lp = this.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
        this.setLayoutParams(lp);
        //The following lines cause the preview to go black
        Display display = ((WindowManager) _appContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        if (display.getRotation() == Surface.ROTATION_0) {
            this.setRotation(90);
        } else if (display.getRotation() == Surface.ROTATION_270) {
            this.setRotation(180);
        }

        _camera.startPreview();
    }
}

那是什么设备?它是Nexus7平板电脑。没有
setRotation()
方法。它继承自
视图
,与此处无关。使用
Camera.setOrientation()