标签在滚动视图部分无法正确显示

问题描述 投票:0回答:1

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

这是我的.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"
kivy python-3.7 kivy-language
1个回答
0
投票

我正在猜测您实际上想要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
© www.soinside.com 2019 - 2024. All rights reserved.