Papotitu
Papotitu

Reputation: 447

Kivy anchor two widget at each side

I'm trying to do a video on top of a graph, with two buttons controlling the graph. I'd like one button to be at the left of the window, the other one at the right, both on the same row, and my problem is placing the - and + buttons. I have the following kv file, the concerned buttons are the two Control class:

#: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



But both Control are taking half the width of the row, whatever I change... Any ideas ?

Upvotes: 0

Views: 602

Answers (2)

John Anderson
John Anderson

Reputation: 38937

You can use an empty Widget to fill the blank space between the Controls like this:

    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

Upvotes: 1

amras
amras

Reputation: 1599

You have to use FloatLayout instead of BoxLayout with correct pos_hint values. Below is the snippet for the button widget part:

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}

Hope this would solve your issue.

Upvotes: 1

Related Questions