Check orientation on Android phone

前端 未结 23 1615
庸人自扰
庸人自扰 2020-11-22 06:26

How can I check if the Android phone is in Landscape or Portrait?

23条回答
  •  [愿得一人]
    2020-11-22 07:18

    i think using getRotationv() doesn't help because http://developer.android.com/reference/android/view/Display.html#getRotation%28%29 getRotation() Returns the rotation of the screen from its "natural" orientation.

    so unless you know the "natural" orientation, rotation is meaningless.

    i found an easier way,

      Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
      Point size = new Point();
      display.getSize(size);
      int width = size.x;
      int height = size.y;
      if(width>height)
        // its landscape
    

    please tell me if there is a problem with this someone?

提交回复
热议问题