【问题标题】:ScrollView recoils/Springs back to top after scrolling down向下滚动后,ScrollView 回弹/弹回顶部
【发布时间】:2021-08-20 01:06:36
【问题描述】:

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

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

我的代码是这样的。这是我的 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]

【问题讨论】:

    标签: kivy scrollview kivy-language


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 2018-11-15
      • 2012-06-15
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多