gpt4 book ai didi

python - Kivys GridLayout 中的 ScrollView

转载 作者:太空宇宙 更新时间:2023-11-03 15:00:50 24 4
gpt4 key购买 nike

这是我的应用程序的 kv 文件

<myAppLayout>       
canvas.before:
Color:
rgba:1, 1, 1,1
Rectangle:
pos: self.pos
size: self.size

ScrollView:
size: self.size
size_hint: (None, None)
GridLayout:
cols:1

TextInput:

pos_hint:{"center_x":0.5,"y":0.1}
color:0,0.5,1,1
background_color:0,0.5,1,1
size:20,20


Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size
Label:
color:1,0,1,1
text:"hello"
text_size:self.size

Python 代码如下所示

class myAppLayout(GridLayout):
pass

问题是我的输出看起来像这样(左下角),而我希望根据设备的大小逐行排列所有内容 enter image description here

最佳答案

如果你想让ScrollView的内容占据所有可用空间,你不能这样做:

size: self.size 
size_hint: (None, None)

另一方面,ScrollView 中的小部件必须具有定义的高度 (size_hint_y = None),否则它们将自动调整其大小以适应 ScrollView 的大小。

请记住,如果您未指定列或行,GridLayout 将引发异常。您必须为 myAppLayout 分配一定数量的行或列。

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder

kv_text = '''

<MyLabel@Label>:
color:1,0,1,1
text:"hello"
text_size:self.size
size_hint_y:None
height: 20

<myAppLayout>
cols: 1
canvas.before:
Color:
rgba:1, 1, 1,1
Rectangle:
pos: root.pos
size: root.size

ScrollView:
GridLayout:
cols:1
size_hint_y: None
height: self.minimum_height

TextInput:
pos_hint:{"center_x":0.5,"y":0.1}
color:0,0.5,1,1
background_color:0,0.5,1,1
size_hint_y: None
height: 30

MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:
MyLabel:

'''

class myAppLayout(GridLayout):
pass

class MyApp(App):
def build(self):
return myAppLayout()

def main():
Builder.load_string(kv_text)
app = MyApp()
app.run()

if __name__ == '__main__':
main()

输出:

enter image description here

关于python - Kivys GridLayout 中的 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45134648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com