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
看