如何增加BoxLayout内mdtextfield的大小 --kivy

问题描述 投票:0回答:1

我想创建一个具有特定size_hintTextfield,一旦字段内的文本达到特定的

minimum height
,文本字段size_hint将被设置为None并且
y_scroll
将被激活..使用
FloatLayout
时看起来很完美。但是当我使用 Boxlayout 时,
MDTextField
的大小似乎没有改变。如果我将其 size_hint 更改为假设
0.7
那么文本字段
Having mode set to rectangle
将成为一条线,如果将其保留为 None 并通过
height
属性更改其高度,则大小不会增加。我该如何解决这个问题。 .除了更改布局之外的任何解决方案,因为只有 BoxLayout 是我想要/使用的东西

我的代码::

str = '''
    
MDCard:
    pos_hint : {'x':0.056 , 'top':0.836}
    size_hint : 0.88,0.82
    
    ScrollView:
        do_scroll_x : False
        BoxLayout:
            height : self.minimum_height
            orientation : 'vertical'
            size_hint : 1,None
            spacing : 15
            padding : 55
            
            MDTextField:
                id : input_field_1
                mode : 'rectangle'
                size_hint : None,None
                height : 500            # setting height doesn't seems to work either
                #y_scroll : True if self.minimum_height > 400 else False
                multiline : True

            MDTextField:
                id : input_field_2
                mode : 'rectangle'
                size_hint : None,0.7 # see the result 
                #y_scroll : True
                multiline : True

'''
class My_4app(MDApp):
    def build(self):
        return Builder.load_string(str)
My_4app().run()

非常感谢任何帮助

python kivy textinput
1个回答
0
投票

已经过去 3 年多了,所以 OP 可能已经弄清楚了这一点。但如果其他人遇到同样的问题,您只需将 MDTextField 中的 max_height 设置为最小值,一旦大小达到该限制,这将强制它滚动。

在上面的代码中,只需替换:

height : 500

max_height : 400

或任何你想要的阈值。

© www.soinside.com 2019 - 2024. All rights reserved.