Position of layouts and widgets in different android phones

15 views
Skip to first unread message

Mateo Aita

unread,
Jun 9, 2020, 9:43:38 AM6/9/20
to Kivy users support
I have been working on a game for android devices using kivy. The problem is that when i tested the apk on different phones, i found out that i do not know how to make the app  look the same in every phone no matter how big or small the screen is. I  used size_hint and pos_hint properties but i really need help to understand how to correct this issue because i thought that those properties would make things look the same on each screen. You can see an example of the trouble i am facing in the picture i sent. In it, you can see that the size of the field image  is not equal to the % of the screen size i want it to be. I think it might be a problem regarding that image. I hope someone could help me, thanks for the time.
foto tact it.png

Elliot Garbus

unread,
Jun 9, 2020, 9:58:53 AM6/9/20
to kivy-...@googlegroups.com

When specifying sizes and positions use the kivy.metrics dp and sp to use size independent pixels.

 

See: https://kivy.org/doc/stable/api-kivy.metrics.html?highlight=kivy%20metrics#module-kivy.metrics

--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6c397fd4-2da5-453e-8f68-dd193e5ed857o%40googlegroups.com.

 

foto tact it.png

Mateo Aita

unread,
Jun 9, 2020, 11:23:20 AM6/9/20
to Kivy users support
how do i use dp to set the widget position?


El martes, 9 de junio de 2020, 10:58:53 (UTC-3), Elliot Garbus escribió:

When specifying sizes and positions use the kivy.metrics dp and sp to use size independent pixels.

 

See: https://kivy.org/doc/stable/api-kivy.metrics.html?highlight=kivy%20metrics#module-kivy.metrics

 

 

 

From: Mateo Aita
Sent: Tuesday, June 9, 2020 6:43 AM
To: Kivy users support
Subject: [kivy-users] Position of layouts and widgets in different android phones

 

I have been working on a game for android devices using kivy. The problem is that when i tested the apk on different phones, i found out that i do not know how to make the app  look the same in every phone no matter how big or small the screen is. I  used size_hint and pos_hint properties but i really need help to understand how to correct this issue because i thought that those properties would make things look the same on each screen. You can see an example of the trouble i am facing in the picture i sent. In it, you can see that the size of the field image  is not equal to the % of the screen size i want it to be. I think it might be a problem regarding that image. I hope someone could help me, thanks for the time.

--
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-...@googlegroups.com.

Elliot Garbus

unread,
Jun 9, 2020, 12:43:45 PM6/9/20
to kivy-...@googlegroups.com

If you have any places where you are using values for offsets,  positions or size use dp.

 

Label:
    size_hint_y: None
    height: dp(48)

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/9b837f25-8bb4-4c9d-a3ce-18443d0418e7o%40googlegroups.com.

 

Mateo Aita

unread,
Jun 9, 2020, 2:22:13 PM6/9/20
to Kivy users support
I use the same logic even for images or buttons? size_hint_y: None and  height: dp()?. because i have tried to run my code using dp in some widgets' position and size, but depending on the phone that i am "simulating", the field can or can not fit in the screen. I was using this code:
size_hint: None, None
size: dp(650), dp(650)
pos: dp(-120), dp(55)

Mateo Aita

unread,
Jun 9, 2020, 2:30:39 PM6/9/20
to Kivy users support
To make myself clear, here are some examples of what's going on
foto tact it.png

Elliot Garbus

unread,
Jun 9, 2020, 2:43:48 PM6/9/20
to kivy-...@googlegroups.com
Share your code that creates the field layout. 

Sent from my iPad

On Jun 9, 2020, at 11:31 AM, Mateo Aita <mate...@gmail.com> wrote:


To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7e7fb042-9962-4056-ac9b-2de53eb1b000o%40googlegroups.com.
<foto tact it.png>

Mateo Aita

unread,
Jun 9, 2020, 2:54:37 PM6/9/20
to Kivy users support

That's it!
foto tact it.png

Elliot Garbus

unread,
Jun 9, 2020, 3:33:20 PM6/9/20
to kivy-...@googlegroups.com

Try this:

 

from kivy.app import App
from kivy.lang import Builder


kv =
"""
RelativeLayout:
    Image:
        source: 'soccer-game.jpg'  # your image here
        allow_stretch: True
        keep_ratio: True
"""

class SizeFieldApp(App):
   
def build(self):
       
return Builder.load_string(kv)

SizeFieldApp().run()

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e0ca616c-6f89-4482-9df2-ec1ad30bc10bo%40googlegroups.com.

 

Mateo Aita

unread,
Jun 9, 2020, 3:44:09 PM6/9/20
to Kivy users support
Oh thank you, do i place all the other widgets inside that rel layout? I don't know how to fix all the other ones (players, points, labels, etc)

Mateo Aita

unread,
Jun 9, 2020, 4:02:14 PM6/9/20
to Kivy users support
well, actually i think the only issue is that i can not make the field adjust to screen size, as in the pic below... if i fix that, i believe everything would be solved. Any ideas? thank you very much Elliot!
foto tact it.png

Elliot Garbus

unread,
Jun 9, 2020, 4:28:35 PM6/9/20
to kivy-...@googlegroups.com
If you want the image to fill the screen
In Image Set
keep_ratio: False
allow_stretch: True


Sent from my iPhone

On Jun 9, 2020, at 1:02 PM, Mateo Aita <mate...@gmail.com> wrote:


To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b671088f-38f4-4d1c-91d5-cb7fc7ddd695o%40googlegroups.com.
<foto tact it.png>

Mateo Aita

unread,
Jun 9, 2020, 4:39:40 PM6/9/20
to Kivy users support
Now it works perfectly, thank you very much!

Elliot Garbus

unread,
Jun 9, 2020, 4:49:14 PM6/9/20
to kivy-...@googlegroups.com

😊

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/10b33406-b6c8-4b74-b682-7e6331a75228o%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages