我正在嘗試在 kivymd 中進(jìn)行網(wǎng)格布局。已創(chuàng)建 GridLayout 但寬度未填滿屏幕。kivymd中如何擴(kuò)展列的寬度以適應(yīng)屏幕?我使用了 kivymd 文檔中的示例并使用它創(chuàng)建了網(wǎng)格布局。app.pyfrom kivymd.app import MDAppfrom kivy.uix.screenmanager import Screen, ScreenManagerfrom kivy.lang import Builderfrom main_screen_str import helper_stringfrom kivy.core.window import WindowWindow.size = (300, 500)class MainScreen(Screen): passclass MainApp(MDApp): def __init__(self, **kwargs): super().__init__(**kwargs) self.sm = ScreenManager() self.sm.add_widget(MainScreen(name="main_screen")) self.main_str = Builder.load_string(helper_string) def build(self): screen = Screen() screen.add_widget(self.main_str) return screenif __name__ == '__main__': MainApp().run()這是構(gòu)建器字符串。網(wǎng)格布局已創(chuàng)建,但寬度不適合屏幕。如何擴(kuò)展網(wǎng)格布局中單個列的寬度?構(gòu)建字符串helper_string = """ScreenManager: MainScreen:<MainScreen>: name: 'main_screen' MDGridLayout: cols: 3 MDIconButton: icon: "android" theme_text_color: "Custom" text_color: app.theme_cls.primary_color MDIconButton: icon: "android" theme_text_color: "Custom" text_color: app.theme_cls.primary_color MDIconButton: icon: "android" theme_text_color: "Custom" text_color: app.theme_cls.primary_color MDIconButton: icon: "android" theme_text_color: "Custom" text_color: app.theme_cls.primary_color MDIconButton: icon: "android" theme_text_color: "Custom" text_color: app.theme_cls.primary_color MDIconButton: icon: "android" theme_text_color: "Custom" text_color: app.theme_cls.primary_color """
1 回答

冉冉說
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個贊
根據(jù)MDIconBuuton 文檔:
默認(rèn)情況下,MDIconButton 按鈕的大小為 (dp(48), dp (48))
并且GridLayout
將使用這些大小值來調(diào)整列的大小。您可以通過調(diào)整 的大小來調(diào)整列大小MDIconButtons
。所以,如果你只是添加:
size_hint_x:?0.33
對于每個MDIconButton
,每列將是 的寬度的三分之一MainScreen
。
添加回答
舉報
0/150
提交
取消