How to detect exact orientation of device in Froyo?

后端 未结 5 1783
执念已碎
执念已碎 2021-01-15 05:18

I\'m trying to temporarily lock the orientation of the Android device, where most of the time it changes with the sensor. So what I want to do is figure out what the current

5条回答
  •  星月不相逢
    2021-01-15 06:00

    I'm not exactly sure what your problem is. Are you trying to determine if a device is currently oriented in landscape or portrait mode? If so you can get that information quickly with:

    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    Point size = new Point();
    Display.getSize(size);
    
    boolean isLandscape = size.x > size.y;
    

    If you couple that with Display.getOrientation() you should have access to all the information you need.

提交回复
热议问题