Relative Layout Positioning Help

66 views
Skip to first unread message

Calum M

unread,
Mar 10, 2020, 10:02:28 AM3/10/20
to Kivy users support
Hi, I've posted a topic to stackoverflow but I don't think the community is very active there. 


Can anyone assist me with this problem?

Elliot Garbus

unread,
Mar 10, 2020, 11:25:34 AM3/10/20
to kivy-...@googlegroups.com

You will get more help if you strip your problem down to a minimal runnable example.

 

Taking a look at your code, you could benefit from different layout choices.

You have used a FloatLayout to position your titles on the top of the screen.  This could be simplified with a BoxLayout, with orientation: ‘horizontal’.

You have put the grid of cameras into a relative layout.  This would be simplified by using a grid layout.

 

https://kivy.org/doc/stable/api-kivy.uix.relativelayout.html?highlight=relativelayout#common-pitfalls

 

I started to fool around with something – but need to run.  This should provide a few ideas:

 

from kivy.app import App
from kivy.lang import Builder

kv =
"""
#: set white 1, 1, 1, 1

<TitleLabel@Label>:
    canvas.before:
        Color:
            rgba: 0.164, 0.2, 0.2666, 1
        Rectangle:
            pos: self.pos
            size: self.size

<OffImage@Image>
    canvas:
        Color:
            rgba: white      
        Line:
            points: self.x, self.y, self.x + self.width, self.y + self.height
           
BoxLayout:
    orientation: 'vertical'
    canvas.before:
        Color:
            rgba: 0.2078, 0.23529, 0.3137, 1
        Rectangle:
            pos: self.pos
            size: self.size
   
    BoxLayout:
        size_hint_y: None
        height: 48
        spacing: 5
        TitleLabel:
            size_hint_x: .6
            text: 'Main Header'
           
        TitleLabel:
            size_hint_x: .3
            text: 'Main Page'
           
        TitleLabel:
            size_hint_x: .1
            text:''
    GridLayout:
        id: grid
        spacing: 5
        padding: 5
        cols: 4
        rows: 3
        OffImage:
            source: '1a.png'           
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
        Image:
            source: '1a.png'
       
"""


class LayoutTest(App):
   
def build(self):
       
return Builder.load_string(kv)

LayoutTest().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d84c0abd-a179-400e-b5ff-a8c557041c7a%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages