How to get screen dimensions as pixels for android devices? (using beeware/toga) #1937
-
Hello, I would like to arrange the widgets differently in toga boxes based on the screen width of android devices. The goal is to adapt the how the widgets are arranged in the UI based on the android phone screen size. Example : if the screen width is more than 600px, I will pack each two buttons in a row box (direction=ROW) and all row boxes in one box with direction=COLUMN. Else, I want all buttons to be packed in one box with direction=COLUMN. I found Q&A on how to get the android screen dimensions in Java here: such as: What would be the solution in python code to get/read the screen dimensions as pixels for android devices? In my attempts to make it work I get errors such as: Thank you in advance for your support :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It's difficult to say what is going wrong when you've only provided a single line of the error message and no Python code; but based on that message, it suggests you're invoking something that is returning a DisplayMetrics object, not a WindowManager object. However - more importantly - a "pixel-by-pixel" layout is almost certainly the wrong way to do layout with Toga, if for no other reason that when you rotate your device, your layout won't work. If you want 2 buttons to share the available horizontal space, you don't find the width, divide by two and set a fixed width on both. Instead, you set both elements to have the same |
Beta Was this translation helpful? Give feedback.
Agreed that adaptive screen layout would be desirable; however, that's definitely outside the capabilities of Pack at present.