简体   繁体   English

所有屏幕的GUI显示布局相同Kivy

[英]GUI Display Layout same for all screens Kivy

Problem is that If i create something on Windows and test same thing on Android Samsung S3 Gui is shows different widgets at different places . 问题是,如果我在Windows上创建内容并在Android上测试相同内容,则三星S3 Gui会在不同位置显示不同的小部件。 For example 例如

1.I created a widget set its size as 800,600 1.我创建了一个小部件,其大小设置为800,600
2.Include a label with size 100,100 3. put it at position 700,10 so it should be visible at lower right corner . 2.包括尺寸为100,100的标签3.将其放在位置700,10,因此应该在右下角可见。

This works ok on windows test environment but when i move code to Samsung S3 using kivy launcher it dosent show label at same position . 这在Windows测试环境下还可以,但是当我使用kivy启动器将代码移至Samsung S3时,它会在同一位置显示标签。

I read about matix doc on http://kivy.org/docs/api-kivy.metrics.html and used following in the code 我在http://kivy.org/docs/api-kivy.metrics.html上了解了matix doc,并在代码中使用了以下内容

import os
os.environ['KIVY_METRICS_DENSITY'] = '1'
os.environ['KIVY_DPI'] = '96'

which was the value in Windows but it dosent seem to work .orifginal values of these in Samsung S3 was KIVY_METRICS_DENSITY =2 KIVY_DPI = 320 Window.size = 1028X728 (i think ) 这是Windows中的值,但似乎没有问题。三星S3中的这些原始值是KIVY_METRICS_DENSITY = 2 KIVY_DPI = 320 Window.size = 1028X728(我认为)

Then i added dp to the values of position and sizes but still it is same on Android . 然后我将dp添加到position和size的值,但在Android上仍然相同。 I know i am missing something . 我知道我想念一些东西。 Can someone advice ? 有人可以建议吗?

Below is the Sample code : 下面是示例代码:

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
import os
os.environ['KIVY_METRICS_DENSITY'] = '1'
os.environ['KIVY_DPI'] = '96'

class Container(Widget):
    def __init__(self, **kwargs):
        super(Container, self).__init__(**kwargs)
        self.size = '800dp','600dp'
        label = Label(text="Am i A Label ?")
        label.size = '100dp','100dp'
        label.pos = '700dp','10dp'
        self.add_widget(label)

class MyJB(App):
    def build(self):

        parent = Container()
        return parent

if __name__ == '__main__':
    MyJB().run()

It sounds like the code is doing exactly what you told it to; 听起来代码正在完全按照您的指示进行操作; placing the label at a specific position in pixels. 将标签放在像素的特定位置。 In the default desktop window this happens to be the bottom left, but on another device (or after resizing the window) it could be anywhere, depending on the resolution of the display. 在默认的桌面窗口中,它恰好位于左下角,但是在另一台设备上(或在调整窗口大小之后),它可能在任何地方,具体取决于显示器的分辨率。

You should instead use layouts, so that everything is set proportionally and will adjust to different screen shapes. 您应该改用布局,以便按比例设置所有内容,并将其调整为不同的屏幕形状。 For instance, you could use an AnchorLayout to place the label in the bottom right. 例如,您可以使用AnchorLayout将标签放置在右下角。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM