Search code examples
androidpythonrotationkivybuildozer

How to identify whether the screen is in Portrait or Landscape in Kivy


I just made an apk app using kivy. In the code, I defined the positions of all widgets according to scale of the screen. However, when I rotate the screen, say, from portrait to landscape, the absolute coordinates still stay the same, and it doesn't fit in very well.

Is there a method to identify whether portrait or landscape is being displayed? I need this in order to re-define the positions of my widget when user rotates the phone.


Solution

  • It would be much better to just not use absolute coordinates, but rather to use kivy's layout classes to achieve relative positioning (you can also specify the relative positioning manually but that's harder and more verbose, and you're just reinventing the layouts if you do it).

    In any case, the direct answer to your question is that there may be an android api function you can call to get the orientation if you really want, or in reality you presumably care specifically about the window size which is exposed by kivy.core.window.Window.size