ScrollView recoils/Springs 向下滚动后回到顶部

ScrollView recoils/Springs back to top after scrolling down

我已将滚动视图添加到我的 kivy 应用程序,但令我惊讶的是,每次我垂直滚动时,屏幕都会自动将我带回输出屏幕的初始位置。有什么方法可以阻止我在我的应用程序中遇到的持续后坐力?

使用以下类型的输入(任何以“,”分隔且没有空格的字符串):“what,do,i,say,about,myself,what,do,i,say,about,myself,what,do ,我,说,关于,我自己,什么,做,我,说,关于,我自己,什么,做,我,说,关于,我自己,什么,做,我,说,关于,我自己,什么,做,我,说,关于,我自己。

我的代码是这样的。这是我的 absl.py 文件。

from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivy.factory import Factory

Window.size = (600, 600)

class HelpWindow(Screen):
    """
    This is a help window. It contains the functionality of all the given boxes
    on the main window.
    """

    def main_window(self):
        sm.current = "main"

class MainWindow(Screen):
    """
    This is the main window that contains the main form.
    This connects the frontend of the app to the backend
    """
    target = ObjectProperty(None)


    def v_popup(self):
        version_popup()
    
    def help(self):
        sm.current = "help"
    
    def output_window(self):
        sm.current = "output"

    def get_results(self):
        out_window = self.manager.get_screen('output')
        out_window.main(self.target.text)
        sm.current = "output"
    

class OutputWindow(Screen):
    """
    This is the output window. All the generated results will be seen here.
    """
    res = ObjectProperty(None)
    res_out = ObjectProperty(None)

    def main(self, options):
        options = list(options.split(","))
        for item in options:
            self.res_out.add_widget(Label(size_hint_y=None,height=30,text=item))
        

    def main_window(self):
        sm.current = "main"

class WindowManager(ScreenManager):
    pass

def version_popup():
    """
    Version Popup Window.
    """
    
    version = "v1.0"
    version_text = "this is "+version+" for this app"
    vpop = Popup(title="Version",
                    content=Label(text=version_text),
                    size_hint=(None, None), size=(400, 400))
    
    vpop.open()

### main builder and WindowManager object
kv = Builder.load_file("start.kv")
sm = WindowManager()

### Adding screens to widget
screens = [MainWindow(name="main"), HelpWindow(name="help"), OutputWindow(name="output")]
for screen in screens:
    sm.add_widget(screen)

sm.current = "main"

### main working
class AnubisApp(App):
    def build(self):
        return sm
        
if __name__ == '__main__':
    AnubisApp().run()

这是我的 start.kv 文件。

<HelpWindow>
    name:"help"

    Button:
        id:ms
        text:"Main Screen"
        on_release:
            root.manager.transition.direction = "left"
            root.main_window()

<MainWindow>
    name:"main"

    target : target
    
    
    GridLayout:
        cols:1

        GridLayout:
            cols:3
            
            row_force_default: True
            row_default_height: 50
            
            Button:
                id:hp
                text:"Help"
                on_release:
                    root.manager.transition.direction = "right"
                    root.help()
            
            Button:
                id:version
                text: "Version"
                on_release: 
                    root.v_popup()
        
        GridLayout:
            cols:2
            row_force_default: True
            row_default_height: 30

            Label:
                text:"Target *"
            TextInput:
                id:target
                multiline:False
            
            
        GridLayout:
            cols:3
            row_force_default: True
            row_default_height: 50

            Label:
                text:""
            
            Button:
                text:"Submit"
                on_release:
                    root.get_results()
            
            Label:
                text:""


<OutputWindow>
    name:"output"
    
    res_out:res_out

    
    GridLayout:
        cols:1

        ScrollView:

            GridLayout:
                id:res_out
                cols : 1
                size_hint_y: None
                
                
        
        Button:
            id:ms
            size_hint_y : .1
            text:"Main Screen"
            on_release:
                root.manager.transition.direction = "right"
                root.main_window()

我猜这个问题可能只是我的系统问题,但我不太确定。此外,设置滚动条的高度、宽度和颜色也不起作用。我在“ScrollView”中添加了几行但没有工作。

ScrollView:
    size_hint : None, None
    height : 150
    width : 20
    bar_color : [.7, .7, .7, .9]

我无法重现后坐力问题,但您必须为 GridLayout 指定高度才能使滚动生效:

        GridLayout:
            id:res_out
            cols : 1
            size_hint_y: None
            height: self.minimum_height  # required to size GridLayout