【问题标题】:MDBottomNavigation tabs positioned incorrectlyMDBottomNavigation 选项卡位置不正确
【发布时间】:2020-12-19 19:57:36
【问题描述】:

我目前正在开发一个具有多个屏幕的应用程序(为此我使用了 ScreenManager)。但是,有一个称为 TravelManagerWindow 的屏幕,它也有一个 MDBottomNavigation 小部件,一个 MDBottomNavigationItem(或屏幕)将用于请求旅行费用,另一个用于在旅行后提供此类费用的证据。

问题是,一旦我进入 TravelManagerWindow,MDBottomNavigation 小部件的选项卡的位置就会不正确。不过,在我手动调整整个应用程序窗口的大小后,选项卡位置会更改为所需的位置。有没有办法确保标签从一开始就正确呈现?我一直在寻找解决方案,但仍然无法解决我的问题。

相关代码如下:

<TravelManagerWindow>:
    name:'travelManager'
    on_enter: root.set_expansion_panel()
    on_enter: root.set_expansion_panel_2()


    BoxLayout:
        orientation: 'vertical'

        MDBottomNavigation:
            id: bottom_Navigation

            MDBottomNavigationItem:
                text: 'Solicitud de Gastos'
                name: 'solicitudes'
                halign:'center'
                icon: 'plus'
    
            MDBottomNavigationItem:
                text: 'Comprobacion de Gastos'
                name: 'comprobacion'
                halign:'center'
                icon: 'format-list-checks'

进入屏幕时标签页的原始位置为:

调整大小后所需的位置是:

编辑

我包含了一个最小的可重现示例。代码如下:

Python 文件:

from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen

class LoginWindow(Screen):
    pass

class BottomNavigationWindow(Screen):
    pass

class WindowManager(ScreenManager):
    pass

ScreenManager().add_widget(LoginWindow(name='login'))
ScreenManager().add_widget(BottomNavigationWindow(name='BottomNav'))

class reprod_example2(MDApp):
    def build(self):
        self.theme_cls.primary_palette = "Teal"
        return WindowManager()


if __name__ == "__main__":
    reprod_example2().run()

KV 文件:

<WindowManager>:
    LoginWindow:
    BottomNavigationWindow:

<LoginWindow>:
    name: 'login'
    MDRaisedButton:
        text: 'Enter'
        pos_hint: {'center_x': 0.5, 'center_y': 0.5}
        size_hint: None, None
        on_release:
            root.manager.transition.direction = 'up'
            root.manager.current = 'BottomNav'

<BottomNavigationWindow>:
    name:'BottomNav'

    MDBoxLayout:

        MDBottomNavigation:
            MDBottomNavigationItem:
                text: 'Page 1'
                name: 'page1'
                MDLabel:
                    pos_hint: {'center_x': 0.5, 'center_y': 0.5}
                    text: 'This is page one'

            MDBottomNavigationItem:
                text: 'Page 2'
                name: 'page2'
                MDLabel:
                    pos_hint: {'center_x': 0.5, 'center_y': 0.5}
                    text: 'This is page two'

在我最小的可重现示例中,我发现了同样的错误。 MDBottomNavigation 定位不正确。手动重塑窗口可以解决问题。但是我希望从一开始就正确绘制 MDBottom 导航。

非常感谢任何建议 提前非常感谢。

【问题讨论】:

    标签: python kivy-language bottomnavigationview kivymd


    【解决方案1】:

    我想通了。我只是在进入 MDBottomNavigation 所在的屏幕之前调整了窗口大小:

    from kivy.core.window import Window
    
    def on_pre_enter(self, *args):
        Window.size = (Window.width + 1, Window.height + 1)
        Window.size = (Window.width - 1, Window.height - 1)
    

    【讨论】:

    • 虽然 id 看起来不像模型解决方案,但它也对我有用。谢谢!
    猜你喜欢
    • 2012-02-04
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多