【问题标题】:Kivy: ScrollView squishes together the layoutKivy:ScrollView 将布局挤压在一起
【发布时间】:2021-01-14 17:10:11
【问题描述】:

我是 Kivy 的新手,这是我第一次尝试创建滚动视图。

我正在尝试进行“拆分”盗版,您可以在其中创建费用并让应用程序确定谁应该支付谁等等。

我正在尝试创建一个方法,该方法可以打开一个包含所有成员及其余额的弹出窗口以及一个带有“结算”文本的按钮。余额下方应该是所有已登记债务的列表,您应该能够向下滚动以查看所有债务。弹出窗口还应该包含一个“取消”按钮。

我的问题是我的代码没有启用滚动功能,并且还会将弹出窗口中的内容压缩在一起。 See picture.

高度赞赏所有帮助!

请参阅下面的(混乱的)代码:

    sbl_ret = GridLayout(cols = 1)

    sbl_balances = GridLayout(cols = 3)

    sbl_balances.add_widget(Label())
    sbl_balances.add_widget(Label(text = 'Balances', font_size = '20sp', size_hint = (1,.2), color = backgroundColor, bold = True))
    sbl_balances.add_widget(Label())

    for member in self.members:

        sbl_balances.add_widget(Label(text = member.getName(), font_size = 40, size_hint_y = None, height = 60))

        sbl_balances.add_widget(Label(text = str(round(member.getBalance())) + ' kr', font_size = 40, size_hint_y = None, height = 60))

        sbl2 = BoxLayout(orientation = 'vertical')
        sbl2.add_widget(Label(size_hint = (1,.2)))
        btn = Button(text = 'Settle up', background_color = buttonColor, bold = True, size_hint_y = None, height = 60)
        btn.bind(on_press = lambda member: self.settleUp())
        sbl2.add_widget(btn)
        sbl2.add_widget(Label(size_hint = (1,.2)))
        sbl_balances.add_widget(sbl2)


    sbl_balances.add_widget(Label(size_hint = (.2,1)))
    sbl_balances.add_widget(Label(text = 'Debts', font_size = '20sp', color = backgroundColor, bold = True))
    sbl_balances.add_widget(Label(size_hint = (.2,1)))
    for member in self.members:
        for debt in member.getDebtList():
            sbl_balances.add_widget(Label(size_hint = (.2,1)))
            sbl_balances.add_widget(Label(size_hint_y = None, height = 60, text = debt.getToWhom().getName() + ' lent ' + str(debt.getAmount()) + ' SEK to ' + debt.getFromWhom().getName() + ' for ' + debt.getDescription(), font_size = 40))
            sbl_balances.add_widget(Label(size_hint = (.2,1)))

    sbl_balances.bind(minimum_height=sbl_balances.setter('height'))

    sbl3 = BoxLayout(size_hint = (1,.15))
    sbl3.add_widget(Label(size_hint = (.2,1)))
    b = Button(text = 'Cancel', background_color = entryColor, size_hint_y = None, height = 150)
    b.bind(on_press = lambda x: self.balanceDialog.dismiss())
    sbl3.add_widget(b)
    sbl3.add_widget(Label(size_hint = (.2,1)))

    sv = ScrollView(do_scroll_x = False)
    sv.add_widget(sbl_balances)

    sbl_ret.add_widget(sv)
    sbl_ret.add_widget(sbl3)


    self.balanceDialog = Popup(title = 'Group view', content = sbl_ret, title_align = 'center',
        title_color = backgroundColor, background_color = [0,0,0,.7], separator_height = 0, title_size = '28sp')
    self.balanceDialog.open()

'''

【问题讨论】:

    标签: kivy scrollview


    【解决方案1】:

    尝试将size_hint_y=None 添加到创建GridLayout 的代码中:

    sbl_balances = GridLayout(cols = 3, size_hint_y=None)
    

    请参阅documentation

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多