kivy - 如何在浮动布局中固定小部件的位置 - kivy
问题描述
我有一个与 pos_hint 和 floatlayout kivy 中的小部件定位有关的大问题。所以现在基本上我有两个 y_scroll 设置为 True 的 MDTextField。这样它们的大小就会在每个包裹上增加。因此这些小部件一个接一个地放置,使得 input_field_1 首先是 input_field_2。这些小部件当然放置在 FlaotLayout 中,而这个 FlaotLayout 位于 ScrollView 中。每当文本字段的高度增加时,它也会导致 floatlayout 的高度增加。所以我的问题是,如果你先写 20 行字段,使其高度比此时增加 20 倍,它将与第二个小部件重叠。并且它们将没有该小部件的迹象。我怎样才能避免这样的事故和任何帮助表示赞赏。
我的代码如下:
str = '''
ScrollView:
do_scroll_x : False
FloatLayout:
height : input_field_1.height + input_field_2.height + 100
size_hint : None,None
MDTextField:
id : input_field_1
mode : 'rectangle'
size_hint : None,None
pos_hint : {'x' : 0.1,'top': 0.8}
y_scroll : True
multiline : True
MDTextField:
id : input_field_2
mode : 'rectangle'
size_hint : None,None
pos_hint : {'x' : 0.1,'top': 0.5}
y_scroll : True
multiline : True
'''
class My_4app(MDApp):
def build(self):
return Builder.load_string(str)
My_4app().run()
如果您认为他们是否有更好的小部件,请建议
解决方案
我认为 aBoxLayout
会做你想做的事。尝试更换:
FloatLayout:
height : input_field_1.height + input_field_2.height + 100
size_hint : None,None
和:
BoxLayout:
orientation: 'vertical'
size_hint: 1, None
height: self.minimum_height
推荐阅读
- c# - mongodb C#驱动程序序列化模型上的动态字段
- r - 如何解决 R 中的线性不等式系统
- api - 使用 Salesforce Bulk API 通过 Azure 数据工厂将数据从 CSV 文件传递到 Salesforce
- javascript - 当输入名称=确认给出确认不是函数时,Javascript返回确认()
- json - PowerBI 将 JSON 记录提取到自定义列
- javascript - 按下按钮时参考另一个网页
- python - 更改选定的 QTab 时更改 QStackedLayout 索引/页面
- r - 如何在带有 vitae 包的 RMarkdown 中的 bib 文件中使用非英文字符?
- reactjs - Safari 不支持 reacstrap 输入日期
- python - 联合概率热图