問題描述
我想創建一個布局,其中我有類似于 BoxLayout 的東西,讓我能夠在我的布局中創建行",并且在每個行"中我想使用另一種 BoxLayout 中的東西來創建列".
I want to create a layout where I have something similar to a BoxLayout to give me the ability to create "rows" in my layout, and in each "row" I want to use something in the sorts of another BoxLayout to create "columns".
列不需要均勻分布.例如,我想創建一個 BoxLayout,其中一列是方形圖像,另一列占據剩余的可用寬度.
The columns don't need to be evenly distributed. For example, I want to create a BoxLayout with one column with a square image, and another occupying the rest of the available width.
在我的 gist 上查看代碼和屏幕截圖:https://gist.github.com/MichaelGradek/e5c50038b947352d9e79
See code and screenshot on my gist: https://gist.github.com/MichaelGradek/e5c50038b947352d9e79
我已經在上面的代碼中完成了基本結構,但除此之外,我希望 BoxLayout 的高度適應孩子的高度.
I have the basic structure done in the code above, but in addition, I want the BoxLayout's height to adapt to the height of the children.
實現這一目標的最佳方法是什么?
What would be the best approach to achieve this?
謝謝!
推薦答案
不要使用 BoxLayout,使用 height: self.minimum_height
的 GridLayout,并手動設置尺寸(每個子小部件的 size_hint_y: None
和 height: some_number
).
Don't use a BoxLayout, use a GridLayout with height: self.minimum_height
, and set a manual size (size_hint_y: None
and height: some_number
) for each child widget.
這篇關于Kivy 布局高度以適應子小部件的高度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!