我正在 kivymd 中制作一个应用程序,其中有一个底部导航栏,其中包含三个底部导航元素(主页、加号、个人资料)。我希望在按下主页时显示一个带有三行头像列表的轮播。但是,如果在导航元素(主页)下编写我的代码,它就会出现在中间。如果我在主 boxlayout 中编写代码,其他按钮的内容就会出现在下面。以下是我的代码,其中 nav 元素下的代码被注释:
from kivymd.app import MDApp
from kivy.core.window import Window
from kivy.lang import Builder
Window.size = (375, 667)
kv = """
BoxLayout:
orientation:'vertical'
padding: 0
MDToolbar:
title: "Ad 'O Square"
md_bg_color: 1, 1, 1, 1
specific_text_color: app.theme_cls.accent_color
elevation: 10
Carousel:
direction: "right"
Image:
source: "Colors/red.jpg"
Image:
source: "Colors/green.png"
Image:
source: "Colors/blue.png"
ThreeLineAvatarListItem:
text: "Product 1"
secondary_text: "Short Text"
tertiary_text: "Rating"
ImageLeftWidget:
source: "Colors/red.jpg"
ThreeLineAvatarListItem:
text: "Product 2"
secondary_text: "Short Text"
tertiary_text: "Rating"
ImageLeftWidget:
source: "Colors/blue.png"
ThreeLineAvatarListItem:
text: "Product 3"
secondary_text: "Short Text"
tertiary_text: "Rating"
ImageLeftWidget:
source: "Colors/green.png"
MDBottomNavigation:
panel_color: 1, 1, 1, 1
MDBottomNavigationItem:
name: 'screen 1'
text: 'home'
icon: 'home'
# Carousel:
# direction: "right"
# Image:
# source: "Colors/red.jpg"
# Image:
# source: "Colors/green.png"
# Image:
# source: "Colors/blue.png"
# ThreeLineAvatarListItem:
# text: "Product 1"
# secondary_text: "Short Text"
# tertiary_text: "Rating"
#
# ImageLeftWidget:
# source: "Colors/red.jpg"
#
#
# ThreeLineAvatarListItem:
# text: "Product 2"
# secondary_text: "Short Text"
# tertiary_text: "Rating"
#
# ImageLeftWidget:
# source: "Colors/blue.png"
#
#
# ThreeLineAvatarListItem:
# text: "Product 3"
# secondary_text: "Short Text"
# tertiary_text: "Rating"
#
# ImageLeftWidget:
# source: "Colors/green.png"
MDBottomNavigationItem:
name: 'screen 2'
icon: 'plus-circle-outline'
MDLabel:
text: "Screen 2"
halign: "center"
MDBottomNavigationItem:
name: 'screen 3'
text: 'profile'
icon: 'account'
MDLabel:
text: 'Profile'
halign: 'center'
"""
class App(MDApp):
def build(self):
self.theme_cls.accent_palette = "Red"
screen = Builder.load_string(kv)
return screen
if __name__ == '__main__':
App().run()