滚动视图部分中的标签未正确显示

Label not showing properly in scrollview section

我的标签的最后几行没有显示。我希望我的标签使用 ScrollView 小部件在我的屏幕上正确显示我试过这个但是 ScrollView 不工作除非它有更多的行但是当我增加行并且当我再次滚动时最后一行没有正确出现。简而言之,我希望随着文本长度的增加,滚动视图可以正确显示标签的每一行,并且段落之间的 space 也不会显示

这是我的 .kv 文件代码

ScreenManager:
    id: screen_manager

    MainScreen:
        name: 'main'

        NavigationLayout:

            ScreenManager:

                Screen:

                    MDToolbar:
                        title: "Story"
                        anchor_title: 'left'
                        pos_hint: {"top": 1}
                        elevation: 10
                        left_action_items: [['menu', lambda x: nav_drawer.set_state()]]

             MDNavigationDrawer:
                    title: 'Story A Day'
                    id: nav_drawer
                    swipe_distance: 10

                    ContentNavigationDrawer:
                        id: content_drawer
                        screen_manager: screen_manager
                        nav_drawer: nav_drawer


<MainScreen>:
    BoxLayout:
        canvas:
            Color:
                rgb: 0, 0, 0, 0
            Rectangle:
                pos: root.pos
                size: root.size
        ScrollView:
            Label:
                text:
                    """
                    A boy and a girl were playing together. The boy
                    had a collection of marbles. The girl has some
                    sweets with her. The boy told the girl that he
                    would give her all his marbles in exchange for the
                    sweets with her. The girl agreed.

                    The boy kept the most beautiful and the biggest
                    marbles with him and gave her the remaining marbles.
                    The girl gave him all her sweets as she promised.
                    That night the girl slept peacefully. But the boy
                    could not sleep as he kept wondering if the girl
                    has hidden some sweets from him the way he had
                    hidden the best marbles from her.

                    Moral of the Story :

                    If you do not give 100 percent in a relationship,
                    you will always kept doubting if the other person
                    has given her / his hundred percent. This is applicable
                    for any relationship like love, employee –
                    employer, friendship, family, countries, etc
                    and the most of the feelings we get now
                    days are just merely just the impact of the
                    surrounding now days we dont have a good
                    feeling that last long
                    and now we have to just name it in that way
                    """
                font_size: '20sp'
                height: self.texture_size[1]
                size: self.texture_size
                text_size: root.width, None
                size_hint_x: 1.0
                size_hint_y: None
                halign: "auto"
                valign: "middle"

我在猜测您真正想要 BoxLayout 的位置,但我会这样做:

ScreenManager:
    id: screen_manager

    MainScreen:

<MainScreen>:
    name: 'main'

    NavigationLayout:
        id: nav_layout

        ScreenManager:

            Screen:

                MDToolbar:
                    id: toolbar
                    title: "Story"
                    anchor_title: 'left'
                    pos_hint: {"top": 1}
                    elevation: 10
                    left_action_items: [['menu', lambda x: nav_drawer.set_state()]]

                BoxLayout:
                    size_hint: 1, None
                    height: root.height - toolbar.height
                    ScrollView:
                        Label:
                            text:
                                """
                                A boy and a girl were playing together. The boy
                                had a collection of marbles. The girl has some
                                sweets with her. The boy told the girl that he
                                would give her all his marbles in exchange for the
                                sweets with her. The girl agreed.

                                The boy kept the most beautiful and the biggest
                                marbles with him and gave her the remaining marbles.
                                The girl gave him all her sweets as she promised.
                                That night the girl slept peacefully. But the boy
                                could not sleep as he kept wondering if the girl
                                has hidden some sweets from him the way he had
                                hidden the best marbles from her.

                                Moral of the Story :

                                If you do not give 100 percent in a relationship,
                                you will always kept doubting if the other person
                                has given her / his hundred percent. This is applicable
                                for any relationship like love, employee –
                                employer, friendship, family, countries, etc
                                and the most of the feelings we get now
                                days are just merely just the impact of the
                                surrounding now days we dont have a good
                                feeling that last long
                                and now we have to just name it in that way
                                """
                            font_size: '20sp'
                            color: 0,0,0,1
                            height: self.texture_size[1]
                            size: self.texture_size
                            text_size: root.width, None
                            size_hint_x: 1.0
                            size_hint_y: None
                            halign: "auto"
                            valign: "middle"

        MDNavigationDrawer:
            title: 'Story A Day'
            id: nav_drawer
            swipe_distance: 10

            ContentNavigationDrawer:
                id: content_drawer
                screen_manager: app.root
                nav_drawer: nav_drawer
    #:import FadeTransition kivy.uix.screenmanager.FadeTransition

ScreenManager:
    id: screens

    FirstScreen:

    AboutUs:
        MDIconButton:
            icon: 'close'
            theme_text_color: "Custom"
            text_color: app.theme_cls.primary_color
            pos_hint: {"center_y": 0.97}
            text_color: 1, 1, 1, 1
            on_release:
                screens.transition.direction = 'right'
                screens.current = "main"

<ContentNavigationDrawer>:
    background_color: 2, 3, 4, 5
    orientation: "vertical"
    padding: "8dp"
    spacing: "8dp"

    AnchorLayout:
        anchor_x: "right"
        size_hint_y: None
        height: avatar.height

        Image:
            id: avatar
            size_hint: None, None
            size: "56dp", "56dp"
            source: "data/logo/kivy-icon-256.png"

        MDLabel:
            anchor_y: 'left'
            text: "[b]Story A Day[/b]"
            theme_text_color: "Custom"
            text_color: 0, 0, 0, 1
            markup: True
            font_style: "H4"
            size_hint_y: None
            height: self.texture_size[1]

    MDLabel:
        text: 'Story A Day'
        font_style: "Button"
        size_hint_y: None
        height: self.texture_size[1]

    ScrollView:
        MDList:
            MDExpansionPanelTwoLine:
                text: 'send us your idea'
                secondary_text: 'email: xxxxx@gmail.com'

                IconLeftWidget:
                    icon: "email"

            TwoLineAvatarListItem:
                text: 'Send us your story'
                secondary_text: 'to: Story_A_Day@gmail.com'

                IconLeftWidget:
                    icon: "email"

            OneLineAvatarListItem:
                text: "About Us"
                on_release:
                    root.nav_drawer.set_state("close")
                    root.screens.transition.direction = 'right'
                    root.screens.current = "main"

                IconLeftWidget:
                    icon: "information"
                    on_release:
                        root.nav_drawer.set_state("close")
                        screens.transition = FadeTransition(duration=0.5)
                        screens.current = "screen1"

<AboutUs>:
    name: 'screen1'
    canvas:
        Color:
            rgba: 0, 0, 0, 1
        Rectangle:
            pos: self.pos
            size: self.size
    Label:
        text_color: 255, 255, 255, 0
        text: """[b]About Us [/b]"""
        markup: True
        font_size: '40sp'
        text_size: None, None
        size_hint: 1, 1.9
        height: self.texture_size[1]

    Label:
        text_color: 255, 255, 255, 0
        font_size: '18sp'
        text_size: self.width, None
        size_hint: 1, 1.5
        height: self.texture_size[1]
        halign: "center"
        valign: "center"
        text:
            """"""

<Share>
    MDFloatingActionButtonSpeedDial:
        data: root.data
        icon: 'share-variant'
        opening_time: 0.5
        callback: root.callback   # on pressing the call stack buttons
        color_icon_root_button: 0, 0, 0, 1  # color of icon of button
        color_icon_stack_button: 0, 0, 0, 1
        hint_animation: True
        rotation_root_button: False


<FirstScreen>:
    name: 'main'

    NavigationLayout:
        id: nav_layout

        ScreenManager:

            Screen:

                MDToolbar:
                    id: toolbar
                    title: "Story"
                    anchor_title: 'left'
                    pos_hint: {"top": 1}
                    elevation: 10
                    left_action_items: [['menu', lambda x: nav_drawer.set_state()]]

                BoxLayout:
                    size_hint: 1, None
                    height: root.height - toolbar.height
                    canvas:
                        Color:
                            rgba: 0, 0, 0, 1
                        Rectangle:
                            pos: self.pos
                            size: self.size
                    ScrollView:
                        Label:
                            text:
                                """
                                A boy and a girl were playing together. The boy
                                had a collection of marbles. The girl has some
                                sweets with her. The boy told the girl that he
                                would give her all his marbles in exchange for the
                                sweets with her. The girl agreed.

                                The boy kept the most beautiful and the biggest
                                marbles with him and gave her the remaining marbles.
                                The girl gave him all her sweets as she promised.
                                That night the girl slept peacefully. But the boy
                                could not sleep as he kept wondering if the girl
                                has hidden some sweets from him the way he had
                                hidden the best marbles from her.

                                Moral of the Story :

                                If you do not give 100 percent in a relationship,
                                you will always kept doubting if the other person
                                has given her / his hundred percent. This is applicable
                                for any relationship like love, employee –
                                employer, friendship, family, countries, etc
                                and the most of the feelings we get now
                                days are just merely just the impact of the
                                surrounding now days we dont have a good
                                feeling that last long
                                and now we have to just name it in that way
                                If you do not give 100 percent in a relationship,
                                you will always kept doubting if the other person
                                has given her / his hundred percent. This is applicable
                                for any relationship like love, employee –
                                employer, friendship, family, countries, etc
                                and the most of the feelings we get now
                                days are just merely just the impact of the
                                surrounding now days we dont have a good
                                feeling that last long
                                and now we have to just name it in that way
                                If you do not give 100 percent in a relationship,
                                you will always kept doubting if the other person
                                has given her / his hundred percent. This is applicable
                                for any relationship like love, employee –
                                employer, friendship, family, countries, etc
                                and the most of the feelings we get now
                                days are just merely just the impact of the
                                surrounding now days we dont have a good
                                feeling that last long
                                and now we have to just name it in that way
                                """
                            font_size: '20sp'
                            text_color: 255,255,255, 0
                            height: self.texture_size[1]
                            size: self.texture_size
                            text_size: root.width, None
                            size_hint_x: 1.0
                            size_hint_y: None
                            halign: "auto"
                            valign: "middle"

        MDNavigationDrawer:
            title: 'Story A Day'
            id: nav_drawer
            swipe_distance: 10

            ContentNavigationDrawer:
                id: content_drawer
                screens: app.root
                nav_drawer: nav_drawer

这是您的 kv 文件,其中 ScreenManager: 规则仅列出了 child Screens:

#:import FadeTransition kivy.uix.screenmanager.FadeTransition

ScreenManager:
    id: screens

    FirstScreen:

    AboutUs:

<ContentNavigationDrawer>:
    background_color: 2, 3, 4, 5
    orientation: "vertical"
    padding: "8dp"
    spacing: "8dp"

    AnchorLayout:
        anchor_x: "right"
        size_hint_y: None
        height: avatar.height

        Image:
            id: avatar
            size_hint: None, None
            size: "56dp", "56dp"
            source: "data/logo/kivy-icon-256.png"

        MDLabel:
            anchor_y: 'left'
            text: "[b]Story A Day[/b]"
            theme_text_color: "Custom"
            text_color: 0, 0, 0, 1
            markup: True
            font_style: "H4"
            size_hint_y: None
            height: self.texture_size[1]

    MDLabel:
        text: 'Story A Day'
        font_style: "Button"
        size_hint_y: None
        height: self.texture_size[1]

    ScrollView:
        MDList:
            MDExpansionPanelTwoLine:
                text: 'send us your idea'
                secondary_text: 'email: xxxxx@gmail.com'

                IconLeftWidget:
                    icon: "email"

            TwoLineAvatarListItem:
                text: 'Send us your story'
                secondary_text: 'to: Story_A_Day@gmail.com'

                IconLeftWidget:
                    icon: "email"

            OneLineAvatarListItem:
                text: "About Us"
                on_release:
                    root.nav_drawer.set_state("close")
                    app.root.transition.direction = 'right'
                    app.root.current = "screen1"

                IconLeftWidget:
                    icon: "information"
                    on_release:
                        root.nav_drawer.set_state("close")
                        app.root.transition = FadeTransition(duration=0.5)
                        app.root.current = "screen1"

<AboutUs>:
    name: 'screen1'
    canvas:
        Color:
            rgba: 0, 0, 0, 1
        Rectangle:
            pos: self.pos
            size: self.size
    MDIconButton:
        icon: 'close'
        theme_text_color: "Custom"
        text_color: app.theme_cls.primary_color
        pos_hint: {"center_y": 0.97}
        text_color: 1, 1, 1, 1
        on_release:
            app.root.transition.direction = 'right'
            app.root.current = "main"
    Label:
        text_color: 255, 255, 255, 0
        text: """[b]About Us [/b]"""
        markup: True
        font_size: '40sp'
        text_size: None, None
        size_hint: 1, None
        height: self.texture_size[1]
        pos_hint: {'top':1}

    Label:
        text_color: 255, 255, 255, 0
        font_size: '18sp'
        text_size: self.width, 100
        size_hint: 1, None
        height: self.texture_size[1]
        halign: "center"
        valign: "center"
        text: 
            """"""

<Share>
    MDFloatingActionButtonSpeedDial:
        data: root.data
        icon: 'share-variant'
        opening_time: 0.5
        callback: root.callback   # on pressing the call stack buttons
        color_icon_root_button: 0, 0, 0, 1  # color of icon of button
        color_icon_stack_button: 0, 0, 0, 1
        hint_animation: True
        rotation_root_button: False


<FirstScreen>:
    name: 'main'

    NavigationLayout:
        id: nav_layout

        ScreenManager:

            Screen:

                MDToolbar:
                    id: toolbar
                    title: "Story"
                    anchor_title: 'left'
                    pos_hint: {"top": 1}
                    elevation: 10
                    left_action_items: [['menu', lambda x: nav_drawer.set_state()]]

                BoxLayout:
                    size_hint: 1, None
                    height: root.height - toolbar.height
                    canvas:
                        Color:
                            rgba: 0, 0, 0, 1
                        Rectangle:
                            pos: self.pos
                            size: self.size
                    ScrollView:
                        Label:
                            text:
                                """
                                A boy and a girl were playing together. The boy
                                had a collection of marbles. The girl has some
                                sweets with her. The boy told the girl that he
                                would give her all his marbles in exchange for the
                                sweets with her. The girl agreed.

                                The boy kept the most beautiful and the biggest
                                marbles with him and gave her the remaining marbles.
                                The girl gave him all her sweets as she promised.
                                That night the girl slept peacefully. But the boy
                                could not sleep as he kept wondering if the girl
                                has hidden some sweets from him the way he had
                                hidden the best marbles from her.

                                Moral of the Story :

                                If you do not give 100 percent in a relationship,
                                you will always kept doubting if the other person
                                has given her / his hundred percent. This is applicable
                                for any relationship like love, employee –
                                employer, friendship, family, countries, etc
                                and the most of the feelings we get now
                                days are just merely just the impact of the
                                surrounding now days we dont have a good
                                feeling that last long
                                and now we have to just name it in that way
                                If you do not give 100 percent in a relationship,
                                you will always kept doubting if the other person
                                has given her / his hundred percent. This is applicable
                                for any relationship like love, employee –
                                employer, friendship, family, countries, etc
                                and the most of the feelings we get now
                                days are just merely just the impact of the
                                surrounding now days we dont have a good
                                feeling that last long
                                and now we have to just name it in that way
                                If you do not give 100 percent in a relationship,
                                you will always kept doubting if the other person
                                has given her / his hundred percent. This is applicable
                                for any relationship like love, employee –
                                employer, friendship, family, countries, etc
                                and the most of the feelings we get now
                                days are just merely just the impact of the
                                surrounding now days we dont have a good
                                feeling that last long
                                and now we have to just name it in that way
                                """
                            font_size: '20sp'
                            text_color: 255,255,255, 0
                            height: self.texture_size[1]
                            size: self.texture_size
                            text_size: root.width, None
                            size_hint_x: 1.0
                            size_hint_y: None
                            halign: "auto"
                            valign: "middle"

        MDNavigationDrawer:
            title: 'Story A Day'
            id: nav_drawer
            swipe_distance: 10

            ContentNavigationDrawer:
                id: content_drawer
                screen_manager: app.root
                nav_drawer: nav_drawer

我注意到你对 AboutUs 做了同样的事情,所以我也修改了它,现在它的所有布局都在 <AboutUs>: 规则中。由于您的 ScreenManager 现在与 Screens 处于不同的规则中,因此您无法使用其 id 访问它(ids 仅在同一规则中有效)。因此 Screen 更改可以使用 app.root.current.

完成

我认为 screen_manager: app.root 不起作用,因为在计算该表达式时 app 尚不可用。