guckmalmensch
guckmalmensch

Reputation: 1181

Kivy MDGridLayout fixed column size

ScrollView:
        MDGridLayout:
            id: grid_module_card
            cols: 3
            padding: 30, 30
            spacing: 30, 30
            size_hint_y: None
            height: self.minimum_height
            adaptive_height: True
            row_default_height: 500
            md_bg_color: 0.708, 0.281, 0.097, 1

I use .add_widget to add customized cells to the layout. When there's only 1 cell in the GridLayout, the cell takes up the whole row, but i only want it to be in the first column, taking up 1/3 of the screen. How can i fix this?

Upvotes: 0

Views: 1118

Answers (1)

John Anderson
John Anderson

Reputation: 39092

You can set col_default_width to the width that you want for each column:

col_default_width: self.width/3

or, perhaps, more accurately:

col_default_width: (self.width - self.padding[0] - self.padding[2] - self.cols * self.spacing[0])/self.cols

There are other possibilities using the cols_minimum and col_force_default Have a look at the GridLayout Documentation.

Upvotes: 1

Related Questions