我有一个基本的应用程序,我需要将我的ScrollView
移动到某个y。
我使用scroll_to()
,但这次,我需要移动到某个位置,计算多个信息。(我没有在the doc中找到它)
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
BoxLayout:
ScrollView:
BoxLayout:
orientation: "vertical"
size_hint_y: None
height: "900dp"
MDLabel:
text: "yolo"
size_hint_y: None
height: "300dp"
MDLabel:
text: "yulu"
MDLabel:
text: "yulu"
MDLabel:
text: "yulu"
MDLabel:
text: "yulu"
MDLabel:
text: "yulu"
MDLabel:
text: "yulu"
'''
class App(MDApp):
def build(self):
self.box = Builder.load_string(KV)
return self.box
App().run()
看起来您需要
scroll_y
参数。这是一个百分比值,指示滚动“向下”的距离从文档中:
https://kivy.org/doc/stable/api-kivy.uix.scrollview.html#kivy.uix.scrollview.ScrollView.scroll_y
因此,如果设置
ScrollView.scroll_y = 0.5
,滚动框将向下滚动一半如果您知道滚动的距离(以像素为单位),则始终可以将上述内容与
convert_distance_to_scroll(dx, dy)
结合起来,(同样来自文档):https://kivy.org/doc/stable/api-kivy.uix.scrollview.html#kivy.uix.scrollview.ScrollView.convert_distance_to_scroll
相关问题 更多 >
编程相关推荐