【发布时间】:2020-06-29 16:15:07
【问题描述】:
我想将开关对齐到 BoxLayout 的左侧。对于标签,我使用以下代码实现了这一点:
text_size: self.size
这会将我的标签文本放在我的 boxlayout 的左下角。但是,我无法使用 switch 小部件 来做同样的事情。我尝试使用 size_hint_x、size、pos 等,但我无法在不影响框大小的情况下正确对齐元素。 目前我的标签已正确对齐,因此我尝试为它们分配 id 并根据标签的当前位置定位开关,如下所示:
BoxLayout:
padding: 100, 0, 0, 0
orientation: 'horizontal'
text_size: self.size
valign: 'middle'
Label:
text: 'this is already correctly aligned'
id: 'labelCorrectlyAligned'
#Some other code
BoxLayout:
padding: 100, 0, 0, 0
orientation: 'horizontal'
#here i need something like text_size: self.size but for switches
Switch:
size_hint_x: labelCorrectlyAligned.pos[0] #this should be the current X-position of the label
#pos_hint_x: labelCorrectlyAligned.pos[0] #didnt work either
【问题讨论】:
标签: python switch-statement position kivy alignment