开发者

android universal landscape check

OK I have an app the uses the magneometer to display a graphic that rotates with the phone (basically a compass).

I have a check that subtracts 90 degrees if it is in landscape mode, bu开发者_开发百科t this only works if it is in the default landscape mode. With 2.1 we now have a universal landscape that you can rotate both ways so I now don't know how to figure out which landscape mode it is in.

Here is my code:

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

Any suggestions on how to tell which landscape mode the phone is in?


Please see this: http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html


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;
      }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜