我在kivy中有一个简单的用户界面,它由一个大的gridlayout中的几个gridlayout组成。
代码
这是接口的kv代码
Builder.load_string('''
<GreyLabel>:
size_hint_y: None
height: 30
canvas.before:
Color:
rgba: .7, .7, .7, 1
Rectangle:
pos: self.pos
size: self.size
<ContainerBox>:
orientation: 'horizontal'
GridLayout:
cols: 1
row_force_default: True
foo: [self.rows_minimum.update({i: x.height}) for i, x in enumerate(reversed(list(self.children)))]
ResizingFrame:
id: Row1
cols: 1
GreyLabel:
text: "Something goes here"
GridLayout:
id: Row2
cols: 1
Label:
height: 30
text: 'Label One'
canvas.before:
Color:
rgba: .4, .4, .4, 1
Rectangle:
pos: self.pos
size: self.size
TextInput:
height: 30
multiline: False
write_tab: False
hint_text: 'Insert one liner'
GridLayout:
id: Row3
cols: 1
Label:
height: 45
text: 'Label two'
Button:
text: 'Button One'
height: 60
GridLayout:
rows: 1
height: 25
Button:
text: 'Button Two'
Button:
text: 'Button three'
''')
注意ResizingFrame
项。这是一个GridLayout
类,代码如下
class ResizingFrame(GridLayout):
c_value = StringProperty('SomeThing goes here')
def __init__(self, **kwargs):
super(ResizingFrame, self).__init__(**kwargs)
Clock.schedule_once(lambda dt: self.adjustHeight(), 1)
def adjustHeight(self):
print("ResizingFrame.adjustHeight() before:", self.height)
self.height = 40
print("ResizingFrame.adjustHeight() after:", self.height)
您可以找到整个代码here。你知道吗
目标
我想改变ResizingFrame
的高度。
界面开始时如下所示:
每当adjustHeight()
运行时,它就会说:
调整框架大小。调整高度()之前:100
调整框架大小。调整高度()之后:40
但由于某种原因,这种高度变化实际上从未发生过。我根本无法改变ResizingFrame
的高度。为什么会这样?我该怎么修?你知道吗
注意
这与this question有关。你知道吗
我怀疑问题与线路有关:foo: [self.rows_minimum.update({i: x.height}) for i, x in enumerate(reversed(list(self.children)))]
这应该将行的最小高度设置为其子行的高度。但正如你在截图1中看到的,这并没有发生。它只是把最小高度设为100,然后我就不能再改变高度了。我甚至不能把身高提高到100以上。只是卡住了。你知道吗
无法更改
ResizingFrame
的大小的原因是它的size_hint
优先于任何大小更改。因此,将adjustHeight
方法修改为:将允许
height
更改生效。你知道吗请注意,如果不将
size_hint_y
设置为None
,您将更改height
属性,并打印更改后的值。但是一旦adjustHeight
方法完成,那么ResizingFrame
高度将重新计算并更改回100。您可以通过多次调用原始的adjustHeight
方法看到这一点(beforeheight
始终是bck to 100)。你知道吗相关问题 更多 >
编程相关推荐