1

好的,我有一个应用程序,它使用磁力计显示随手机旋转的图形(基本上是指南针)。

如果它处于横向模式,我有一个检查减去 90 度,但这仅在它处于默认横向模式时才有效。有了 2.1,我们现在有了一个可以双向旋转的通用景观,所以我现在不知道如何确定它处于哪种景观模式。

这是我的代码:

 int test = getResources().getConfiguration().orientation;
 if(Configuration.ORIENTATION_LANDSCAPE == test) {
            rotation = -90f;
        }
        else {
            rotation = 0f;
        }
canvas.rotate((float) (-Math.toDegrees(mOrientation[0]) + rotation ));

关于如何判断手机处于哪种横向模式的任何建议?

4

2 回答 2

1

请看这个:http ://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html

于 2010-11-28T23:10:46.170 回答
0
private static final int ORIENTATION_90 = 1;
private static final int ORIENTATION_0 = 0;
private static final int ORIENTATION_180 = 2;
private static final int ORIENTATION_270 = 3;

switch (orientation)
    {
      default:
      case ORIENTATION_0: // Portrait
        //dostuff
        break;
      case ORIENTATION_90: // Landscape left
        //do stuff
        break;
      case ORIENTATION_180: // Upside down.
        //do stuff
        break;
      case ORIENTATION_270: // Landscape right
        //do stuff
        break;
      }
于 2010-11-28T22:00:04.470 回答