我用Python(test.py)和kivy(test.kv)编写了一些代码。
谁能告诉我如何在我的boxLayout中添加垂直滚动条?
我正在使用
滚动型:
do_scroll_y:真实
do_scroll_x:错误
BoxLayout的:
方向:“垂直”
但我想也许我在某个地方犯了错误。
当我使用scrollView时,设计被破坏
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (600, 700)
class ACgroup(Screen):
pass
class TestACgroup(App):
def build(self):
self.root = Builder.load_file('test.kv')
return self.root
if __name__ == '__main__':
TestACgroup().run()
<CustomLabel@Label>:
text_size: self.size
#padding_x: 5
<SingleLineTextInput@TextInput>:
multiline: False
<GreenButton@Button>:
background_color: 1, 1, 1, 1
size_hint_y: None
height: self.parent.height * 0.100
ACgroup:
BoxLayout:
orientation: "vertical"
GridLayout:
cols: 2
padding : 15, 15
spacing: 20, 5
row_default_height: '20dp'
size_hint: 1, .01
pos_hint: {'x': 0, 'y':.95}
CustomLabel:
text: 'Fname'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 7
Label:
text: 'Name'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
SingleLineTextInput:
id: stateName
GridLayout:
cols: 4
padding : 15, 10
spacing: 20, 5
row_default_height: '20dp'
size_hint: 1, .01
pos_hint: {'x': 0, 'y':.7}
CustomLabel:
text: 'ADDRESS :-'
CustomLabel:
CustomLabel:
CustomLabel:
CustomLabel:
text: 'City'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 4.5
Label:
text: 'Pin'
text_size: self.size
valign: 'middle'
halign: 'right'
SingleLineTextInput:
id: stateCode
CustomLabel:
text: 'Area'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 4.5
GridLayout:
cols: 6
padding: 15, 15
spacing: 5, 5
row_default_height: '20dp'
size_hint: 1, .005
pos_hint: {'x': 0, 'y':.5}
CustomLabel:
text: 'Address'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
#size_hint_y: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 3
#size_hint_y: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 3
#size_hint_y: 0
GridLayout:
cols: 2
padding : 15, 5
spacing: 10, 10
row_default_height: '20dp'
size_hint: 1, .02
pos_hint: {'x': 0, 'y':.4}
CustomLabel:
text: 'CONTACT DETAIL:-'
CustomLabel:
Label:
text: 'Phone'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 6.5
#size_hint_y: 2
Label:
text: 'Mobile'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 6.5
#size_hint_y: 2
Label:
text: 'E-Mail'
text_size: self.size
halign: 'left'
valign: 'middle'
size_hint_x: 2
SingleLineTextInput:
id: acGroup
size_hint_x: 6.5
#size_hint_y: 2
GreenButton:
text: 'Ok'
GreenButton:
text: 'Cancel'
on_press: app.stop()
有人可以帮助我吗?
答案 0 :(得分:1)
当您使用垂直滚动视图时,您必须设置唯一的孩子的高度,如下所示:
ScrollView:
BoxLayout:
size_hint_y: None
height: #the height that you want