我的 RelativeLayout 显然忽略了我的 pos_hint

My RelativeLayout apparently ignores my pos_hint

我一直在尝试为我的应用程序制作 GUI,并且我了解了一些有关 RelativeLayout 的知识。
根据我的理解,您定义了一个变量“pos_hint”,并分配了一个从 0 到 1 的值,表示它与该位置的接近程度。例如。 “右”:1 == 100% 向右

问题是,我有一个垂直的 BoxLayout,包含 2 个 RelativeLayout,其中包含小部件,其中一个也有自己的 RelativeLayout。
这变得非常复杂,我正在努力寻找问题的答案。

我的 objective 是:
“SuspectGraph”在顶部中间,包含 2 个相互重叠的椭圆。
右上角的“设置按钮”。
“MoodButton”在 y 中间,底部框 x 的 1/4
“FoodButton”在 y 中间,底部框 x 的 3/4

从完整的答案到关于如何修复错误的轻微提示,我们将不胜感激。

编辑:忘记添加代码。对不起。

<MainLayout>:
    canvas:
        Color:
            rgba: 1, 1, 1, 1
        Rectangle:
            pos: 0,0
            size: self.width,self.height
    BoxLayout:
        size: self.parent.size
        orientation: "vertical"
        RelativeLayout:
            canvas:
                Color:
                    rgba: 1,0,0,1
                Rectangle:
                    size: self.width,self.height
            size: self.parent.size
            SettingButton:
                size: 50,100
                pos_hint: {'right':1,'y':1}
                Button:
                    text: "Settings"
                    size: self.size
            SuspectGraph:
                pos_hint: {'center_x':1,'center_y':1}
                RelativeLayout:
                    GraphInnerCircle:
                        pos_hint: {'center_x':1,'center_y':1}
                        size: 200,200
                        canvas:
                            Color:
                                rgba: .5,.5,.5,1
                            Ellipse:
                                size: self.size
                    GraphOuterCircle:
                        pos_hint: {'center_x':1,'center_y':1}
                        size: 300,300
                        canvas:
                            Color:
                                rgba: .3,.3,.3,1
                            Ellipse:
                                size: self.size
        RelativeLayout:
            MoodButton:
                size: 50,100
                pos_hint:{'left':.1,'center_y':.7}
                Button:
                    text: "Register Mood"
            FoodButton:
                size: 50,100
                pos_hint:{'right':.1,'center_y':.7}
                Button:
                    text: "Register Food"

问题在于属性如何在嵌套小部件上工作。
以这个片段为例:

        size: self.parent.size
        orientation: "vertical"
        RelativeLayout: 
            canvas:
                Color:
                    rgba: 1,0,0,1
                Rectangle:
                    size: self.width,self.height
            size: self.parent.size
            SettingButton:
                size: 50,100
                pos_hint: {'right':1,'y':1}
                Button:
                    text: "Settings"
                    size: self.size

第 12 行的 pos_hint 适用于小部件“SettingButton”,但不适用于 里面的按钮。 我不知道为什么,但这就是它的工作原理。

尝试将 pos_hint 直接设置为 Button 不起作用,因为它会尝试从 SettingButton 推断其位置,这不是布局。

解决方案
将 SettingButton 的 python 边代码更改为按钮而不是小部件。
将 pos_hint 直接应用到 SettingButton。

希望这可以帮助任何谷歌搜索相同问题的人!