开发者

Stopping surface view from rotating when displaying camera preview

I have a surface view displaying a camera preview which looks good in landscape mode, but when I rotate my phone to portrait the surface view rotates and the camera preview is on its side which looks wrong.

When I fix my application orientation to landscape in my AndroidManifest.xml, th开发者_JAVA百科e surface view behaves how I want it to, in that it doesn't rotate and the camera preview works great.

The problem is that I have other objects on the screen which need to rotate with the phone's orientation, which now doesn't because I've set the orientation to landscape.

Can anyone help me with a way to get everything apart from the surface view to rotate when the phone rotates, or if that is not possible a way to get the current physical orientation of the phone when the applications orientation is set to landscape, so that I can rotate my other objects manually.

Thanks, Andrew


Camera.Parameters have a setRotation() method. Use it to rotate the camera when you change from landscape to portrait and vice versa. Then you don't have to bother about separating your layouts from the surface view.


public void surfaceDestroyed(SurfaceHolder holder){
    if(mCamera!=null){ 
        mCamera.stopPreview(); 
        mCamera.setPreviewCallback(null); 
        mCamera.release();       
        mCamera=null; 

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜