Python pos的相对布局位置问题

Python pos的相对布局位置问题,python,kivy,android-relativelayout,kivy-language,Python,Kivy,Android Relativelayout,Kivy Language,我希望得到有关相对布局位置的提示 def new_game(self): box = BoxLayout(orientation='vertical', size_hint=(.7, .8), pos_hint=({'center_x': .5, 'center_y': .5})) left_box = BoxLayout(size_hint_x=.3) right_box = BoxLayout(size_hint_x=.7) top_box = BoxLayo

我希望得到有关相对布局位置的提示

def new_game(self):
    box = BoxLayout(orientation='vertical', size_hint=(.7, .8), pos_hint=({'center_x': .5, 'center_y': .5}))
    left_box = BoxLayout(size_hint_x=.3)
    right_box = BoxLayout(size_hint_x=.7)
    top_box = BoxLayout(orientation='horizontal', size_hint_y=.85)
    bottom_box = RelativeLayout(size_hint_y=.15)
    bottom_box.add_widget(Button(size_hint=(.3, .7), pos_hint=({'center_x': .5, 'center_y': .5}),
                          on_release=lambda x: self.carousel.load_previous(), text='Начать игру'))
    top_box.add_widget(left_box)
    top_box.add_widget(right_box)
    box.add_widget(top_box)
    box.add_widget(bottom_box)
    return box
在向层添加帧后,我看到该位置发生了位移

<RelativeLayout>
    canvas.before:
        Color:
            rgba: 1, 1, 1, 1
        Line:
            width: 1
            rectangle: self.x, self.y, self.width, self.height

在以下情况之前:
颜色:
rgba:1,1,1,1
行:
宽度:1
矩形:self.x、self.y、self.width、self.height
以下是图片:
RelativeLayout
中的坐标是相对于
RelativeLayout
的原点的。因此,当您在
self.pos
处绘制一个
矩形时,它实际上从
RelativeLayout
的位置偏移了
self.pos
值。您可能想要:

<RelativeLayout>
    canvas.before:
        Color:
            rgba: 1, 1, 1, 1
        Line:
            width: 1
            rectangle: 0, 0, self.width, self.height

在以下情况之前:
颜色:
rgba:1,1,1,1
行:
宽度:1
矩形:0,0,self.width,self.height