Kivy: 将 BoxLayout 对齐到另一个 BoxLayout 的右侧

huangapple go评论96阅读模式
英文:

Kivy: Algining BoxLayout to the right of another BoxLayout

问题

我尝试将一个 BoxLayout 对齐到另一个 BoxLayout 的右上角,但它只会出现在第一个 BoxLayout 的下方。

这是我目前的情况:

这是我想要实现的:

我从类似的问题中了解到可以使用 pos_hint 来完成这个任务,但目前没有任何 pos_hint 的组合可以让我实现这个目标。

我的当前 KV 代码如下:

<DashboardScreen>:
    BoxLayout:
        orientation: "vertical"
        canvas:
            Color:
                rgba: utils.get_color_from_hex("#0b172e")
            Rectangle:
                size: self.size
                pos: self.pos
        Spacer:
            size_hint: (1, 0.04)

        BoxLayout:
            orientation: "vertical"
            size_hint: (0.98, 0.90)
            pos_hint: {"right": 0.99}

            BoxLayout:
                orientation: "horizontal"
                size_hint: (0.03, 0.9)
                canvas:
                    Color:
                        rgba: utils.get_color_from_hex("#1b203e")
                    RoundedRectangle:
                        size: self.size
                        pos: self.pos
                Spacer:
                    size_hint: (0.3, 1)

            BoxLayout:
                orientation: "horizontal"
                size_hint: (0.8, 0.35)
                pos_hint: {"right": 0.99}
                pos_hint: {"top": 0.99}
                spacing: "5"
                canvas:
                    Color:
                        rgba: utils.get_color_from_hex("#1b203e")
                    RoundedRectangle:
                        size: self.size
                        pos: self.pos

任何帮助将不胜感激。

英文:

I'm trying to align a BoxLayout to the upper right of another BoxLayout, but I can only get it to appear underneath the first BoxLayout.

Kivy: 将 BoxLayout 对齐到另一个 BoxLayout 的右侧

This is what I'm trying to achieve:

Kivy: 将 BoxLayout 对齐到另一个 BoxLayout 的右侧

I've read from similar questions this can be done with pos_hint, but no combination of pos_hints currently let me do this.

My current KV code is as follow:

&lt;DashboardScreen&gt;:
BoxLayout:
	orientation: &quot;vertical&quot;
	canvas:
		Color:
			rgba: utils.get_color_from_hex(&quot;#0b172e&quot;)
		Rectangle:
			size: self.size
			pos: self.pos
	Spacer:
		size_hint: (1, 0.04)
	
	BoxLayout:
		orientation: &quot;vertical&quot;
		size_hint: (0.98, 0.90)
		pos_hint: {&quot;right&quot;: 0.99}
		
		BoxLayout:
			orientation: &quot;horizontal&quot;
			size_hint: (0.03, 0.9)
			canvas:
				Color:
					rgba: utils.get_color_from_hex(&quot;#1b203e&quot;)
				RoundedRectangle:
					size: self.size
					pos: self.pos
			Spacer:
				size_hint: (0.3, 1)
		
		BoxLayout:
			orientation: &quot;horizontal&quot;
			size_hint: (0.8, 0.35)
			pos_hint: {&quot;right&quot;: 0.99}
			pos_hint: {&quot;top&quot;: 0.99}
			spacing: &quot;5&quot;
			canvas:
				Color:
					rgba: utils.get_color_from_hex(&quot;#1b203e&quot;)
				RoundedRectangle:
					size: self.size
					pos: self.pos

Any help would be really appreciated.

答案1

得分: 1

只需将封装的 "BoxLayout" 的 "orientation" 更改为 "horizontal":

BoxLayout:
    orientation: "horizontal"
    size_hint: (0.98, 0.90)
    pos_hint: {"right": 0.99}
英文:

Just change the orientation of the enclosing BoxLayout to horizontal:

BoxLayout:
    orientation: &quot;horizontal&quot;
    size_hint: (0.98, 0.90)
    pos_hint: {&quot;right&quot;: 0.99}

huangapple
  • 本文由 发表于 2023年3月8日 19:37:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75672529.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定