android 获取屏幕角度方向

转动方向

//int angle = mActivity.getWindowManager().getDefaultDisplay().getRotation();
或者
int angle = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
switch (angle) {
	case Surface.ROTATION_0:
		Log.d(TAG, "Rotation_0");
		mshow_rotation.setText(Integer.toString(0)+"℃");
		break;
	case Surface.ROTATION_90:
		Log.d(TAG, "ROTATION_90");
		mshow_rotation.setText(Integer.toString(90)+"℃");
		break;
	case Surface.ROTATION_180:
		Log.d(TAG, "ROTATION_180");
		mshow_rotation.setText(Integer.toString(180)+"℃");
		break;
	case Surface.ROTATION_270:
		Log.d(TAG, "ROTATION_270");
		mshow_rotation.setText(Integer.toString(270)+"℃");
		break;
	default:
		Log.d(TAG, "Default Rotation!");
		break;
}

记录

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注