How to really simulate a smartphone screen in kivy?

463 views
Skip to first unread message

Claver Barreto

unread,
Jun 13, 2023, 11:37:48 AM6/13/23
to Kivy users support
Hello mates. So I'm having this problem for a while, but I've always found a workaround, but now there's no use.
How can we really simulate our devices when writing apps?
Like, I know using metrics like "dp()" in the sizes of our widgets helps, but still this does not seem enough.
I am developing this game and I took the resolution of iPhone X's viewport size(375x812) with a ppi or dpi of 458 to be the ideal screen resolution for the app.
Now, how can I simulate this on my computer while writing the app, so I can avoid the stress of compiling with buildozer everytime I change a thing to see if the changes are great with the screen resolution of my smartphone device?
What I tried up until now is not something that works perfectly but kept me going thus far, up until now whenever I tried to run my app I would do this:

KIVY_DPI=458 KIVY_METRICS_DENSITY=0.91 python main.py --size 375x812

This was not perfect, but it was somewhat workable, but now I have several labels in MDCards that are not in place.
Usually I would compile with buildozer, see if the widgets are in place and the sizes are right, if not, then I would change it, compile it again and repeat this process until done. But now I have a lot of labels to use this method.

After searching for a bit, I found a StackOverflow post in which this was used to run a kivy app to simulate a phone's resolution:

python main.py --size=375x812 --dpi=458

it did change a bit the screen size of the app in my computer, but still the changes did not match my smartphone at all.
Now, if anyone has any ideas, I would be forever grateful. Sorry for the long message.
Here are some pictures comparing the app launching in my computer and in 2 smartphone devices:

Computer with:
KIVY_DPI=458 KIVY_METRICS_DENSITY=0.91 python main.py --size 375x812
computer.png


Smartphone 1:
smartphone_A.jpg

Smartphone 2:
smartphone_B.jpg

Robert

unread,
Jun 13, 2023, 12:32:59 PM6/13/23
to Kivy users support
Perhaps the difference is the way the layout is defined?
https://github.com/Android-for-Python/Android-for-Python-Users#layout

Ovide

unread,
Jun 13, 2023, 12:46:06 PM6/13/23
to kivy-...@googlegroups.com
Have You use FloatLayout? 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/cf224c6f-7671-4fe9-965a-afd9a7e5a909n%40googlegroups.com.

Claver Barreto

unread,
Jun 13, 2023, 1:38:02 PM6/13/23
to Kivy users support
it says in the guide: "A truly elastic layout has only hints, and no sizes. In practice this may not look good in all cases. So we must specify the size of some widgets, but this requires the other widgets to be more elastic."
for every widget that i've set the size, i usually go with:
size_hint: None, None
size: dp(width), dp(height)

i thought by using dp(), the size of the widgets would be set approximately based on the device's resolution. I'll try some experiments, hopefully i can find something that will make the process easier.

Claver Barreto

unread,
Jun 13, 2023, 1:42:13 PM6/13/23
to Kivy users support
so i have a ScrollView(so i can scroll through the cards) which has a GridLayout(to place the cards), inside the GridLayout i have the MDCards, and inside this i have a FloatLayout for the labels and the iconbuttons.
kinda like this:

ScrollView:
    GridLayout:
        MDCard:
            FloatLayout:
                Label:
                MDIconButton:

if you want me to provide a code so you can run or  read for youself, let me know.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages