Home > Blockchain >  Scroll view and screen manager
Scroll view and screen manager

Time:11-16

I am trying to write my first app with kivyMD and I faced a problem I am using Screen manager and I have two screens "Home" and "second", In the "second" screen I am using scroll view and when scrolling to the bottom of screen then press a button to back to "Home" screen then again go to "second" screen it open's in the place where I scrolled(in the bottom) . What can I do to make "second" screen always start from the top of screen(not where I left scrolling)? Thank you very much for every answer.

Here is my kv file:


<second>:
    name: "second"
    ScrollView:  
        size: self.size
        GridLayout:
            size_hint_y: None
            height:self.minimum_height  
            width: self.minimum_width
            cols: 1
            padding: "5dp"
            MDCard:

                orientation: "vertical"
                size_hint: 1, None
                height: "1000dp" 
                elevation: 80 
              
                MDFlatButton:
                    text : 'Home'
                    size_hint_y : 0.1
                    on_press :
                        app.root.current = "Home" 
                        root.manager.transition.direction= "right"

CodePudding user response:

You can use the scroll_to method of ScrollView.

scroll_to(widget, padding=10, animate=True)

https://kivy.org/doc/stable/api-kivy.uix.scrollview.html#kivy.uix.scrollview.ScrollView.scroll_to

Call the scroll_to method on the ScrollView from the button that shows the screen screen. You will have to give the ScrollView a name and the first Widget a name so you can reference them.

I can't give a relevant example without seeing your Python code.

  • Related