Search code examples
pythonkivypython-3.6kivy-languagekivymd

MDExpansionPanel content is auto increasing


When I open the panel after closing it, the content increases in size and pushes the rest panels downward, and takes even more space when I close and open the panel again. Below is the code i uses

class PanelPage(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        layout = MDGridLayout()
        layout.cols = 1
        scrollview = ScrollView()
        mdlist = MDList()

        panel = MDExpansionPanel(icon='images/hair1.jpeg',
                                 content=HairStyles(),
                                 panel_cls=MDExpansionPanelOneLine(text='Hairs'))
        mdlist.add_widget(panel)

        panel1 = MDExpansionPanel(icon='images/hair2.png',
                                  content=AfroHair(),
                                  panel_cls=MDExpansionPanelOneLine(text='Afro'))
        mdlist.add_widget(panel1)

        scrollview.add_widget(mdlist)
        layout.add_widget(scrollview)
        self.add_widget(layout)


class WelcomePage(Screen):
    pass


class HairStyles(Screen):
    pass


class AfroHair(Screen):
    pass

Solution

  • in .kv file:

    ...
    <HairStyles>:
        size_hint_y:None
        height: '100sp'
    ...
    ...
    <AfroHair>:
        size_hint_y:None
        height: '100sp'
    ...