我在surfaceView中显示相机预览。在表面回调中,我在surfaceChanged函数中有以下代码:
if(getResources().getConfiguration().orientation== getResources().getConfiguration().ORIENTATION_LANDSCAPE)
camera.setDisplayOrientation(0);
else
camera.setDisplayOrientation(90);
这工作ok,它旋转相机在纵向方向。但当我将平板电脑旋转180度时,预览的方向是错误的。是否有一个属性来决定平板是向上还是向下,这样我就可以相应地改变方向。
您可以使用getRotation()
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getRotation();