【发布时间】:2020-11-10 07:23:54
【问题描述】:
我正在尝试创建一个滚动视图,其中包含两列,在每个“类别”中,它们下面有 4-5 个图标+下标,由一个简单的标题分隔。我将所有 ImageButtons 与每个带有 FloatLayout 的 Image 按钮的下标对齐,所有这些都在 GridLayout 内部(只有一列)。
我的问题是如何更改第一行的高度(主标题),以及包含每个类别标题的行 - 每个类别的次要较小字体标题,(包含按钮 + 对应的行的高度下标是完美的)。
到目前为止,要让我的滚动视图工作,我必须有一个 row_default_height 值,否则我所有的行都被堆叠... 而且由于默认情况下所有行的高度相同,这会留下很多空白空间,我想成为一个较小的标题。
这是我目前所得到的:
'''
:
FloatLayout:
canvas:
Color:
rgb: utils.get_color_from_hex("#69B3F2")
Rectangle:
size: self.size
pos: self.pos
ScrollView:
pos_hint: {"top": 1,"right":1}
size_hint: 1,1
GridLayout:
cols: 1
size_hint_y: None
height: self.minimum_height
row_default_height: '100dp'
spacing: 10,10
row_force_default: False
FloatLayout:
Label:
font_color:
utils.get_color_from_hex("#424FFF")
id: general_relativity_label
font_size: 25
font_name: "Rubik-Bold.ttf"
text: "Calculator (by Gleb)"
pos_hint: {"top": 0.9, "left": 1}
markup: True
FloatLayout:
pos_hint: {"top": 0.9,"right":1}
size_hint: 1,0.225
ImageButton:
pos_hint: {"top": 0.8, "right":.85}
size_hint: 0.2, 0.7
source: "Icons4/014-gravity.png"
on_release:
app.change_screen("kinematics_screen", direction='right', mode='push')
ImageButton:
pos_hint: {"top": 0.8, "right": 0.35}
size_hint: 0.2, 0.7
source: "Icons4/019-relativity.png"
on_release:
app.change_screen("relativity_screen", direction='right', mode='push')
Label:
pos_hint: {"top": 0.1, "right": .85}
size_hint: .2,0.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Kinematics"
markup: True
Label:
pos_hint: {"top": 0.1,"right": 0.35}
size_hint: .2,0.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Relativity"
markup: True
FloatLayout:
pos_hint: {"top": 0.675, "left":1}
size_hint: 1,0.225
#Quantum Tunneling, Energy of H atom
ImageButton:
pos_hint: {"top":0.8,"right":.85}
size_hint: .2,.7
source: "Icons4/049-atom.png"
on_release:
app.change_screen("quantum_screen", direction='right', mode='push')
ImageButton:
pos_hint: {"top": 0.8, "right":0.35}
size_hint: .2,.7
source: "Icons4/046-transverse wave.png"
on_release:
print("Waves")
Label:
pos_hint: {"top": 0.1,"right":.85}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Quantum"
markup: True
Label:
pos_hint: {"top": 0.1,"right":.35}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Waves"
markup: True
FloatLayout:
pos_hint: {"top": 0.450,"left":1}
size_hint: 1,.225
ImageButton:
pos_hint: {"top": 0.8,"right":.85}
size_hint: .2,.7
source: "Icons4/034-orbit.png"
on_release:
print("Astronomy")
ImageButton:
pos_hint: {"top": 0.8,"right":.35}
size_hint: .2,.7
source: "Icons4/018-clamp.png"
on_release:
print("Forces")
Label:
pos_hint: {"top": 0.1,"right":.85}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Astro"
Label:
pos_hint: {"top": 0.1,"right":.35}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Forces"
FloatLayout:
pos_hint: {"top": 0.675, "left":1}
size_hint: 1,0.225
ImageButton:
pos_hint: {"top":0.8,"right":.85}
size_hint: .2,.7
source: "Icons4/049-atom.png"
on_release:
app.change_screen("quantum_screen", direction='right', mode='push')
ImageButton:
pos_hint: {"top": 0.8, "right":0.35}
size_hint: .2,.7
source: "Icons4/046-transverse wave.png"
on_release:
print("Waves")
Label:
pos_hint: {"top": 0.1,"right":.85}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Quantum"
markup: True
Label:
pos_hint: {"top": 0.1,"right":.35}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Waves"
markup: True
FloatLayout:
pos_hint: {"top": 0.450,"left":1}
size_hint: 1,.225
ImageButton:
pos_hint: {"top": 0.8,"right":.85}
size_hint: .2,.7
source: "Icons4/034-orbit.png"
on_release:
print("Astronomy")
ImageButton:
pos_hint: {"top": 0.8,"right":.35}
size_hint: .2,.7
source: "Icons4/018-clamp.png"
on_release:
print("Forces")
Label:
pos_hint: {"top": 0.1,"right":.85}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Astro"
Label:
pos_hint: {"top": 0.1,"right":.35}
size_hint: .2,.15
font_color:
utils.get_color_from_hex("#425FFF")
font_size: 18
text: "Forces"
'''
提前致谢! p.s -> 对 kivy 很陌生,但我可以自信地说我已经用谷歌搜索了很多,但无法找到解决方案..
【问题讨论】:
标签: python kivy scrollview row-height