Kivy在每侧锚定两个小部件

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

我正在尝试在图形上方制作视频,并用两个按钮控制图形。我希望一个按钮在窗口的左侧,另一个在右侧,都在同一行,而我的问题是放置-和+按钮。我有以下kv文件,关注的按钮是两个Control类:

#:kivy 1.0.9

<Control>

    canvas:
        Rectangle:
            size: 5, 5
            pos: self.pos



<VideoWidget>:
    video_player: video_handler
    graph: graph_handler
    data_plus: ctr_plus_handler
    data_minus: ctr_minus_handler

    BoxLayout:
        orientation: 'vertical'

        VideoHandler:
            id: video_handler
            state: 'play'
            options: {'allow_stretch': True}
            size_hint: 1, 0.45
            on_touch_down: root.test()
            on_position: root.move()

        BoxLayout:
            size_hint: 1, 0.1
            orientation: 'horizontal'

            Control:
                id: ctr_minus_handler
                size_hint: 0.1, 1

                pos_hint: {'left': 0.1}


            Control:
                id: ctr_plus_handler
                size_hint: 0.1, 1
                pos_hint: {'right': 0.1}



        GraphWidget:
            id: graph_handler
            size_hint: 1, 0.45



但是无论我更改了什么,两个控件都占据了行的一半宽度...有什么想法吗?

python kivy kivy-language
2个回答
1
投票

您可以使用空白的Widget来填充Controls之间的空白,如下所示:

    BoxLayout:
        size_hint: 1, 0.1
        orientation: 'horizontal'

        Control:
            id: ctr_minus_handler
            size_hint: 0.1, 1
        Widget:
            size_hint: 0.8, 1
        Control:
            id: ctr_plus_handler
            size_hint: 0.1, 1

0
投票

您必须使用FloatLayout而不是BoxLayout带有正确的pos_hint值。以下是按钮小部件部分的代码段:

FloatLayout:
    size_hint: 1, 0.1
    orientation: 'horizontal'
    Control:
        id: ctr_minus_handler
        size_hint: 0.1, 1
        pos_hint: {'left': 1}

    Control:
        id: ctr_plus_handler
        size_hint: 0.1, 1
        pos_hint: {'right': 1}

希望这可以解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.