英文:
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.
This is what I'm trying to achieve:
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:
<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
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: "horizontal"
size_hint: (0.98, 0.90)
pos_hint: {"right": 0.99}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论