Kivy ScrollView窗口小部件设置

时间:2020-07-21 09:49:05

标签: python-3.x scroll kivy scrollview kivy-language

我是Kivy的新手,我正在尝试为一个简单应用程序使用ScrollView功能。最初,我尝试在滚动视图中设置一个框布局,并在该框布局中添加了子窗口小部件以获得滚动效果,但是它不起作用。尝试了几种size_hint组合,但无济于事。然后我在Stackoverflow上遇到了这个answer,并将BoxLayout转换为1列的GridLayout。

现在,滚动效果可以正常工作,但是自定义窗口小部件不会像盒子布局那样水平居中。我还想将滚动区域(视口)限制在锚点布局中位于屏幕右下角的加号按钮正上方。有人可以建议我如何实现这一目标吗?我的代码在下面共享:

Python

class StatusRecord(BoxLayout):
    pass

Kivy

<SivaStatusScreen>:
    dropdown: dropdown.__self__
    name: 'status_screen'
    canvas.before:
        Color:
            rgba: 255/255, 255/255, 255/255, 1
        Rectangle:
            pos: self.pos
            size: self.size
    BoxLayout:
        id: status_layout
        orientation: 'vertical'
        BoxLayout:
            id: actionbar_layout
            size_hint_y: None   # size the box layout to contain the action bar
            height: 48      # width of the action bar in line with the minimum dimensions of the icons
            ActionBar:
                id: status_actionbar
                pos_hint: {'top': 1}
                background_image: ''
                background_color: 195/255, 60/255, 35/255, 1
                ActionView:
                    use_separator: True
                    ActionPrevious:
                        title: 'SIVA'
                        with_previous: False
                    ActionOverflow:
                    CustomActionButton:
                        id: status-button
                        important: True
                        source: {'normal': 'images/communicationgreen-48.png', 'down': 'images/communication-48.png'} [self.state]
                        on_release: root.to_statusscreen()
                    CustomActionButton:
                        id: accounts-button
                        important: True
                        source: {'normal': 'images/key-48.png', 'down': 'images/keygreen-48.png'} [self.state]
                        on_release: root.to_accountsscreen()
                    CustomActionButton:
                        id: bot-button
                        important: True
                        source: {'normal': 'images/bot-48.png', 'down': 'images/botgreen-48.png'} [self.state]
                        on_release: root.to_botscreen()
                    CustomActionButton:
                        id: logout-button
                        important: True
                        source: {'normal': 'images/shutdown-48.png', 'down': 'images/shutdowngreen-48.png'} [self.state]
                        on_release: root.to_logout()
        BoxLayout:
            id: status_display
            # size_hint is not needed. This Layout shares space with the BoxLayout that has a fixed y size, it will grow to fill the space.
            orientation: 'vertical'
            BoxLayout:
                id: status_label
                size_hint_y: None
                height: 40
                orientation: 'horizontal'
                BoxLayout:
                    orientation: 'horizontal'
                    Image:
                        keep_ratio: True
                        source: 'images/communication-48.png'
                    Label:
                        text: 'Status'
                        markup: True
                        color: 0, 0, 0, 1
                ImageLabelButtonTop:
                    # conflict in the on_release defined for ImageLabelButton and this instance.
                    id: parent_button
                    source: 'images/expand-arrow-48.png'
                    text: 'User'
                    on_release:
                        # root.add_dd_values()
                        dropdown.open(self)
                    on_parent: dropdown.dismiss()
                    size_hint_y: None
                    height: '40dp'
                DropDown:
                    id: dropdown
                    on_select:
                        # args is a reserved keyword which returns only two values: object alias (0) and data (1).
                        parent_button.text = args[1][0]
                        parent_button.source = args[1][1]
                        # Invoked inside dropdown
                        # root - Screen, self - DropDown object
                    ImageLabelButton:
                        source: 'images/t-circled-48.png'
                        text: 'Twitter'
                    ImageLabelButton:
                        source: 'images/l-circled-48.png'
                        text: 'LinkedIn'
            ScrollView:
                do_scroll_x: False
                do_scroll_y: True
                GridLayout:
                    id: status_content
                    cols: 1
                    height: self.minimum_height
                    pos_hint: {'center_x':0.5}
                    size_hint_x: 0.95
                    size_hint_y: None
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
                    StatusRecord:
    AnchorLayout:
        id: status_add
        anchor_x: 'right'
        anchor_y: 'bottom'
        ImageButton:
            id: status_addbtn
            source: {'normal': 'images/plus-96.png', 'down': 'images/plusblue-96.png'} [self.state]
            size_hint: 0.2, 0.2
            on_release: root.new_status_entry()

屏幕截图

enter image description here

我想实现两件事:

  1. 将定制小部件(可滚动)水平居中,以使小部件边框可见。
  2. 限制滚动区域/视口在屏幕右下角的绿色加号按钮上方结束。

我们将不胜感激您提供的任何帮助或见识。

0 个答案:

没有答案
相关问题