【问题标题】:How to fix the position of a widget in floatlayout - kivy如何在浮动布局中固定小部件的位置 - kivy
【发布时间】:2020-11-18 14:48:20
【问题描述】:

我有一个与 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()

如果您认为他们是否有更好的小部件,请提出建议

【问题讨论】:

    标签: kivy position


    【解决方案1】:

    我认为BoxLayout 可以满足您的需求。尝试替换:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2017-08-10
      • 1970-01-01
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多