例如,我启动应用程序,然后设备并排旋转 90 度。我想为设备上的每个平面检测此事件。
			
			19124 次
		
4 回答
            18        
        
		
您可以像这样获取屏幕方向(例如在您的 onResume() 方法中):
private static final int ORIENTATION_0 = 0;
private static final int ORIENTATION_90 = 3;
private static final int ORIENTATION_270 = 1;
Display display = ((WindowManager)
          getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenOrientation = display.getRotation();
switch (screenOrientation)
{
default:
case ORIENTATION_0: // Portrait
   // do smth.
break;
case ORIENTATION_90: // Landscape right
   // do smth.
break;
case ORIENTATION_270: // Landscape left
   // do smth.
break;
}
    于 2012-12-11T09:42:25.650   回答
    
    
            0        
        
		
我认为您必须使用传感器管理器来计算每个点的 x,y,z。并使用方程找到两点之间的角度。考虑你的起点(0,0,0);
于 2012-12-11T10:39:31.640   回答
    
    
            0        
        
		
使用 SensorManager 和 TYPE_GYROSCOPE/TYPE_ROTATION_VECTOR/TYPE_ORIENTATION/ 来获取这些值。
查看此页面了解详情。
于 2012-12-11T10:31:35.130   回答
    
    
            0        
        
		
您可以将OrientationEventListener用于飞机
OrientationEventListener mOrientationListener = new OrientationEventListener(
            getApplicationContext()) {
        @Override
        public void onOrientationChanged(int orientation) {
        }
    };
    if (mOrientationListener.canDetectOrientation()) {
        mOrientationListener.enable();
    }
    于 2021-03-09T18:15:46.910   回答