'Issue with screen size on Android
I have a problem with screen size in multiple devices. I have developed my app using Kivy framework and everything is pretty fine on my PC, but when I tried to compile my app to apk file I found that there is an issue with screen size, all elements located in wrong positions and size of every elements (text, button etc.) is not correctly adapted to android. My code is below:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen
from kivy.core.audio import SoundLoader
from kivy.config import Config
from kivy.metrics import dp
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
class LanguagePage(Screen):
def __init__(self, **kwargs):
super(LanguagePage, self).__init__(**kwargs)
self.cols = 1
self.im = Image(source='temp_logo.png')
self.im.size_hint = (dp(100), dp(100))
self.im.pos_hint = {"center_x": 0.5, "center_y": 0.80}
self.add_widget(self.im)
self.app_text = Label(font_size=dp(16),
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
"\nincididunt ut labore et dolore magna"
"\n"
"\naliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco "
"\nlaboris nisi ut aliquip ex ea commodo consequat.",
color='white',
halign='center')
self.app_text.pos_hint = {"center_x": 0.5, "center_y": 0.65}
self.add_widget(self.app_text)
self.button1 = Button(text='Button 1', background_color='06ecfc')
self.button2 = Button(text='Button 2', background_color='06ecfc')
self.button3 = Button(text='Button 3', background_color='FC9106')
self.button1.size_hint = (dp(0.15), dp(0.05))
self.button2.size_hint = (dp(0.15), dp(0.05))
self.button3.size_hint = (dp(0.15), dp(0.05))
self.button1.pos_hint = {"center_x": 0.5, "center_y": 0.48}
self.button2.pos_hint = {"center_x": 0.5, "center_y": 0.42}
self.button3.pos_hint = {"center_x": 0.5, "center_y": 0.3}
self.button2.bind(on_press=self.screen_transition_2)
self.button2.bind(on_press=self.btn_pressed)
self.button3.bind(on_press=self.btn_pressed)
self.button3.bind(on_press=self.quit_app)
self.add_widget(self.button1)
self.add_widget(self.button2)
self.add_widget(self.button3)
self.button1.bind(on_press=self.screen_transition)
self.button1.bind(on_press=self.btn_pressed)
self.music = SoundLoader.load('bg_music.mp3')
self.music.loop = True
self.music.play()
def btn_pressed(self, instance):
self.sound = SoundLoader.load('click.wav')
self.sound.play()
def screen_transition(self, *args):
self.manager.current = 'new page'
def screen_transition_2(self, *args):
self.manager.current = 'next page'
def quit_app(self, instance):
App.get_running_app().stop()
Window.close()
Recently I have found that there is make a sense to use dp(size) from kivy.metrix lib, and I changed my code using this library but nothing is changed and my app is not correctly displayed on my Android app. I am attaching the scrrenshots from PC and my Android device. Please check my code and my screenshots and let me know how can I fix it? How can I adapt my code for every devices. The screenshots are below:


Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
