Adding grid layout in scroll view.

586 views
Skip to first unread message

Rohan Khedekar

unread,
Oct 17, 2020, 11:24:26 AM10/17/20
to Kivy users support
I wanted to make a scrollable grid layout for my app. But I was unable to do so on my own. Following is a simple piece of code written by me for creating a scrollable grid layout.
import kivymd
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.list import OneLineListItem
from kivymd.uix.label import MDLabel
text1='''
Screen:
    ScrollView:
        MDGridLayout:
            id:grid1
            cols:1
            padding:(10,10)
            spacing:(10,10)
            row_default_height:100
'''
class myapp(MDApp):
    def build(self):
        self.t1=Builder.load_string(text1)
        for i in range(50):
            self.t1.ids['grid1'].add_widget(MDLabel(text=str(i+1)))
        return self.t1
myapp().run()


This code creates the grid, but I'm not able to scroll through it. Later I made following changes to my builder string and I got necessary results from the code.

text1='''
Screen:
    ScrollView:
        MDGridLayout:
            id:grid1
            cols:1
            padding:(10,10)
            spacing:(10,10)
            row_default_height:100
            adaptive_height:True
'''

Can you guys tell me what actually is this 'adaptive_height' attribute of 'MDGridLayout' class? How setting it to true allowed me to scroll through my grid layout?
A help from your side will be appreciated.

Thanks and Regards,
Rohan Khedekar.

Elliot Garbus

unread,
Oct 17, 2020, 2:07:23 PM10/17/20
to kivy-...@googlegroups.com

I don’t use kivymd, but I was curious so I looked at the kivymd docs: https://kivymd.readthedocs.io/en/latest/components/gridlayout/index.html?highlight=adaptive_height#adaptive-height

 

adaptive_height: True

Equivalent

size_hint_y: None
height: self.minimum_height

For the gridlayout to scroll it needs a fixed size, the size_hint needs to be set to None, adaptive_height did that for you.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e22d36a1-8a4d-41fa-967e-a09c3ccca2c7n%40googlegroups.com.

 

Rohan Khedekar

unread,
Oct 17, 2020, 6:32:53 PM10/17/20
to kivy-...@googlegroups.com
Okay... Thank you Elliot for helping me out with this.

Reply all
Reply to author
Forward
0 new messages