简体   繁体   English

Android:如何忽略围绕单轴的旋转?

[英]Android: how to ignore rotation around single axis?

I'm developing application, where activity starts after phone's rotation. 我正在开发应用程序,在手机旋转后开始活动。 When you rotate phone backward that activity have to finish. 向后旋转手机时,该活动必须完成。 Is it possible to ignore rotation around other axes? 是否可以忽略围绕其他轴的旋转?

You can check which way the phone is held with this: 您可以通过以下方式检查手机的固定方式:

Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();

Then you can check the orientation like this: 然后,您可以像这样检查方向:

switch (rotation)
{
    case Surface.ROTATION_90:
        ...
        break;
    case Surface.ROTATION_180:
        ...
        break;
    case Surface.ROTATION_270:
        ...
        break;
    default:
        ...
        break;
}

(Note that for pre-API 8 versions you'd need to use display.getOrientation() instead of display.getRotation() ) (请注意,对于API 8之前的版本,您需要使用display.getOrientation()而不是display.getRotation()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM