pos的相对布局位置问题
Relative layout position problem with pos
希望得到相对布局位置的提示。
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
图片如下:
Relative layout
RelativeLayout
中的坐标是相对于RelativeLayout
的原点的。因此,当您在 self.pos
处绘制 Rectangle
时,无论 self.pos
值是多少,它实际上都会从 RelativeLayout
的位置偏移。你可能想要:
<RelativeLayout>
canvas.before:
Color:
rgba: 1, 1, 1, 1
Line:
width: 1
rectangle: 0, 0, self.width, self.height
希望得到相对布局位置的提示。
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
图片如下: Relative layout
RelativeLayout
中的坐标是相对于RelativeLayout
的原点的。因此,当您在 self.pos
处绘制 Rectangle
时,无论 self.pos
值是多少,它实际上都会从 RelativeLayout
的位置偏移。你可能想要:
<RelativeLayout>
canvas.before:
Color:
rgba: 1, 1, 1, 1
Line:
width: 1
rectangle: 0, 0, self.width, self.height