当我运行下面的代码时,我不能滚动。我想滚动整个屏幕。你知道吗
我怎样才能做到这一点?你知道吗
from kivy.base import runTouchApp
#kivy.require("1.8.0")
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.config import Config
from kivy.uix.scrollview import ScrollView
from kivy.properties import StringProperty
Config.set('graphics', 'window_state', 'maximized')
Builder.load_string('''
<ScrollableLabel>:
FloatLayout:
AsyncImage:
source:'' #html here
allow_stretch: True
keep_ratio: False
pos_hint: {"top": 1, 'right':1}
size_hint: 1, 1
AsyncImage:
source:'' #html here
allow_stretch: True
keep_ratio: True
pos_hint: {"top": 1, 'right':0.13}
size_hint: 0.15, 0.15
Label:
color: [66/255,134/255,244/255,1]
height: 40
font_size: 25
italic: 1
bold: 1
text: 'testing'
pos_hint: {"top": 0.96, 'right': 0.24}
size_hint: 0.1, 0.1
Label:
color: [66/255,134/255,244/255,1]
height: 40
font_size: 50
italic: 1
bold: 1
text: 'Testing\\nTesting1\\nTesting2\\nTesting3\\nTesting4'
pos: root.x, root.y+25
size_hint: 0.1, 0.1
''')
class ScrollableLabel(ScrollView):
text = StringProperty('')
if __name__ == "__main__":
runTouchApp(ScrollableLabel())
所有的东西都会显示,但滚动条不会。你知道吗
我找到了答案。你知道吗
首先,您必须设置
size_hint: (1, None)
,这样您就可以设置height: 40
,它决定您可以滚动多长时间。你知道吗如果不知道要设置多长时间,可以这样设置:
height: sum([c.height for c in self.children])
ScrollView
的子级必须至少将size_hint
的一部分设置为None
,否则默认的size_hint: 1,1
会使子级的大小与ScrollView
相同,因此没有可滚动的内容。因此,只需将ScrollableLabel
规则的初始部分更改为:我对
3000
的选择是任意的,只是为了确保FloatLayout
大于ScrollView
。而且bar_width
使滚动条更容易查看。你知道吗相关问题 更多 >
编程相关推荐