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 . For example

1.I created a widget set its size as 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 .

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 .

I read about matix doc on http://kivy.org/docs/api-kivy.metrics.html and used following in the code

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 )

Then i added dp to the values of position and sizes but still it is same on 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top