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

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

Kivy: Algining BoxLayout to the right of another BoxLayout

问题

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

这是我目前的情况:

这是我想要实现的:

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

我的当前 KV 代码如下:

  1. <DashboardScreen>:
  2. BoxLayout:
  3. orientation: "vertical"
  4. canvas:
  5. Color:
  6. rgba: utils.get_color_from_hex("#0b172e")
  7. Rectangle:
  8. size: self.size
  9. pos: self.pos
  10. Spacer:
  11. size_hint: (1, 0.04)
  12. BoxLayout:
  13. orientation: "vertical"
  14. size_hint: (0.98, 0.90)
  15. pos_hint: {"right": 0.99}
  16. BoxLayout:
  17. orientation: "horizontal"
  18. size_hint: (0.03, 0.9)
  19. canvas:
  20. Color:
  21. rgba: utils.get_color_from_hex("#1b203e")
  22. RoundedRectangle:
  23. size: self.size
  24. pos: self.pos
  25. Spacer:
  26. size_hint: (0.3, 1)
  27. BoxLayout:
  28. orientation: "horizontal"
  29. size_hint: (0.8, 0.35)
  30. pos_hint: {"right": 0.99}
  31. pos_hint: {"top": 0.99}
  32. spacing: "5"
  33. canvas:
  34. Color:
  35. rgba: utils.get_color_from_hex("#1b203e")
  36. RoundedRectangle:
  37. size: self.size
  38. 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:

  1. &lt;DashboardScreen&gt;:
  2. BoxLayout:
  3. orientation: &quot;vertical&quot;
  4. canvas:
  5. Color:
  6. rgba: utils.get_color_from_hex(&quot;#0b172e&quot;)
  7. Rectangle:
  8. size: self.size
  9. pos: self.pos
  10. Spacer:
  11. size_hint: (1, 0.04)
  12. BoxLayout:
  13. orientation: &quot;vertical&quot;
  14. size_hint: (0.98, 0.90)
  15. pos_hint: {&quot;right&quot;: 0.99}
  16. BoxLayout:
  17. orientation: &quot;horizontal&quot;
  18. size_hint: (0.03, 0.9)
  19. canvas:
  20. Color:
  21. rgba: utils.get_color_from_hex(&quot;#1b203e&quot;)
  22. RoundedRectangle:
  23. size: self.size
  24. pos: self.pos
  25. Spacer:
  26. size_hint: (0.3, 1)
  27. BoxLayout:
  28. orientation: &quot;horizontal&quot;
  29. size_hint: (0.8, 0.35)
  30. pos_hint: {&quot;right&quot;: 0.99}
  31. pos_hint: {&quot;top&quot;: 0.99}
  32. spacing: &quot;5&quot;
  33. canvas:
  34. Color:
  35. rgba: utils.get_color_from_hex(&quot;#1b203e&quot;)
  36. RoundedRectangle:
  37. size: self.size
  38. pos: self.pos

Any help would be really appreciated.

答案1

得分: 1

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

  1. BoxLayout:
  2. orientation: "horizontal"
  3. size_hint: (0.98, 0.90)
  4. pos_hint: {"right": 0.99}
英文:

Just change the orientation of the enclosing BoxLayout to horizontal:

  1. BoxLayout:
  2. orientation: &quot;horizontal&quot;
  3. size_hint: (0.98, 0.90)
  4. 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:

确定