Goal : Make my application fit all android devices
I am trying to build a game using kivy and KivyMD and I don't know how precisely how to make my code fit all android devices.
In the kivyMD documentation, devs use often the "dp" metric (Density-independent Pixels) to describe the size of widgets.
When I use python3 main.py -m screen:note2,portrait
to view how my app would look like on a note2 with the code below, the layout appears as I would like but the problem occurs when I use a device with a different screen density (say 3 or 1) (https://github.com/kivy/kivy/blob/master/kivy/modules/screen.py). 8 times out 10 my app look great on a device with a screen density of 2, but for the other screen densities, should I make different versions of my code ?
For example, with screen densities of 2, I could use :
size: "280dp", "180dp"
When the density is 1, I could use something like :
size: "140dp", "90dp"
etc...
I really would like to know what is the correct way to do this. Thanks in advance
main.py
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
Screen:
MDCard:
orientation: "vertical"
padding: "8dp"
size_hint: None, None
#Those dimensions look great when the density is two AND Width of the screen is less than 1920
size: "280dp", "180dp"
pos_hint: {"center_x": .5, "center_y": .5}
MDLabel:
text: "Title"
theme_text_color: "Secondary"
size_hint_y: None
height: self.texture_size[1]
MDSeparator:
height: "1dp"
MDLabel:
text: "Body"
'''
class TestCard(MDApp):
def build(self):
return Builder.load_string(KV)
TestCard().run()