我想在一个屏幕上使用两个分割器,这样用户可以使用3个部分中的任何一个来填充整个屏幕(但是留下一些可以显示分割器)。
我已经尝试过(参见下面的代码),但是当我将第3部分缩小到最小然后尽可能地扩大第1部分时,第3部分消失了,这不是理想的行为(我喜欢它对所有3个部分都是对称的。)
有没有人有想法?
BoxLayout:
id: all
min_view_size: sp(30)
strip_size: sp(13)
Splitter:
sizable_from: 'right'
strip_size: all.strip_size
max_size: all.width - (all.min_view_size + all.strip_size)*2
min_size: all.min_view_size + all.strip_size
Label:
text: '1'
Splitter:
sizable_from: 'right'
strip_size: all.strip_size
max_size: all.width - (all.min_view_size + self.strip_size)*2
min_size: all.min_view_size + self.strip_size
Label:
text: '2'
BoxLayout:
max_size: all.width - (all.min_view_size + all.strip_size)*2
min_size: all.min_view_size
Label:
text: '3'
答案 0 :(得分:1)
经过一些调整后,这是一个2个水平分割器的工作示例,因此它们之间的部分具有最小尺寸:
BoxLayout:
id: all
min_view_size: sp(30)
strip_size: sp(13)
Splitter:
id: splitter1
sizable_from: 'right'
strip_size: all.strip_size
max_size: all.width - (all.min_view_size + all.strip_size)*2
min_size: all.min_view_size + all.strip_size
Label:
text: '1'
Splitter:
id: splitter2
sizable_from: 'right'
strip_size: all.strip_size
max_size: (all.width - splitter1.width) - (all.min_view_size + self.strip_size)
min_size: all.min_view_size + self.strip_size
Label:
text: '2'
BoxLayout:
Label:
text: '3'
诀窍是让第二个拆分器的min_size规则取决于第一个拆分器的大小。
修改强>
这里是窗口窄/宽时的自动定位调整:
BoxLayout:
id: all
min_view_size: sp(30)
strip_size: sp(13)
orientation: 'vertical' if self.width < self.height else 'horizontal'
vertical: self.orientation == 'vertical'
bigger_size: self.height if self.vertical else self.width
default_part_size: (self.bigger_size - self.strip_size*2)/3
# Reset part sizes when orientation changes
on_vertical:
if args[1]: (splitter1.height, splitter2.height) = (self.default_part_size, self.default_part_size)
if not args[1]: (splitter1.width, splitter2.width) = (self.default_part_size, self.default_part_size)
Splitter:
id: splitter1
strip_size: all.strip_size
max_size: all.bigger_size - (all.min_view_size + all.strip_size)*2
min_size: all.min_view_size + all.strip_size
sizable_from: 'bottom' if all.vertical else 'right'
size_hint: (1, None) if all.vertical else (None, 1)
size: (all.width, all.default_part_size) if all.vertical else (all.default_part_size, all.height)
BoxLayout:
Button:
text: '1'
Splitter:
id: splitter2
strip_size: all.strip_size
splitter1_bigger_size: splitter1.height if all.vertical else splitter1.width
max_size: (all.bigger_size - self.splitter1_bigger_size) - (all.min_view_size + self.strip_size)
min_size: all.min_view_size + self.strip_size
sizable_from: 'bottom' if all.vertical else 'right'
size_hint: (1, None) if all.vertical else (None, 1)
size: (all.width, all.default_part_size) if all.vertical else (all.default_part_size, all.height)
BoxLayout:
Button:
text: '2'
BoxLayout:
Button:
text: '3'