如何设置 ThreeLineAvatarIconListItem 的宽度?

问题描述

您好,ThreeLineAvatarIconListItem 的设置有问题。

我会告诉你

enter image description here

我该如何解决这个问题?

列表未定义,应用程序将连接到服务器并获取列表,连接后,对于我从服务器收到的列表中的所有项目,我向 MDList 添加一个小部件,这工作正常,但 scondary_text 最终位于右侧容器上的小部件下方,代码如下:

class ListItem(ThreeLineAvatarIconListItem):
    def on_size(self,ins,value):
        for child in self.children:
            for childs in child.children:
                try:
                    if str(childs.icon) == 'plus':
                        plus = childs.width
                    if str(childs.icon) == 'minus':
                        minus = childs.width
                        self.ids._right_container.width = (minus + plus)
                        self.ids._right_container.x = (minus + plus)
                except:
                    continue

class LeftLabel(ILeftBodyTouch,MDLabel):
    disabled = True

class RightPlusWidget(IconRightWidget):
    def on_release(self):
        global dict_ordine
        n = 0
        for tree in ((self.parent).parent).children:
            for label in tree.children:
                n = n + 1
                if n == 4:
                    prezzo = float(label.text[:-4])
                if n == 6:
                    dict_ordine[label.text] = {}
                    dict_ordine[label.text]['quantita'] = quantita
                    dict_ordine[label.text]['prezzo'] = prezzo
                if label.disabled == True:
                    label.text = str(int(label.text) + 1)
                    quantita = str(label.text)

class RightMinusWidget(IconRightWidget):
    def on_release(self):
        global dict_ordine
        n = 0
        for tree in ((self.parent).parent).children:
            for label in tree.children:
                n = n + 1
                if n == 6:
                    if quantita == '0':
                        try:
                            del dict_ordine[label.text]
                        except:
                            continue
                    else:
                        dict_ordine[label.text]['quantita'] = quantita
                if label.disabled == True:
                    if int(label.text) <= 0:
                        label.text = '0'
                        quantita = str(label.text)
                    else:
                        label.text = str(int(label.text) - 1)
                        quantita = str(label.text)

这些是要添加到 MDList 的小部件类。 而以下代码用于将小部件添加到 MDList 并且所有代码都有效。

def add_widget(dt,widget,wid,*largs):
    widget.add_widget(wid)

def add_widget_f(dt,indez,*largs):
    widget.add_widget(wid,index=indez)
        
def init_menu(self,menu,refresh):
    _ = 0
    
    if refresh == 1:
        while len(LST_BEVANDE.children) != 0:
            for child in LST_BEVANDE.children:
                LST_BEVANDE.remove_widget(child)
        while len(LST_CIBO.children) != 0:
            for child in LST_CIBO.children:
                LST_CIBO.remove_widget(child)
        while len(LST_BAR.children) != 0:
            for child in LST_BAR.children:
                LST_BAR.remove_widget(child)
        _ = 1
    else:
        _ = 1

    if _ == 1:
        dict_menu = menu.split('|')
        menu1 = eval(dict_menu[0])
        menu2 = eval(dict_menu[1])
        menu3 = eval(dict_menu[2])

        NoI = 0
        for child in menu1:
            if str(menu1[child]['icon']) == 'cart-off':
                widget = ListItem()
                widget.text = str(menu1[child]['titolo'])
                widget.secondary_text = str(menu1[child]['desc'])
                widget.tertiary_text = str(menu1[child]['prezzo'])
                left_w = LeftLabel()
                left_w.text = '0'
                right_w = IconRightWidget()
                right_w.icon = 'food-off'
                Clock.schedule_once(partial(self.add_widget,left_w),0.01)
                Clock.schedule_once(partial(self.add_widget,right_w),0.02)
                Clock.schedule_once(partial(self.add_widget_f,LST_BEVANDE,NoI),0.03)
                NoI = NoI + 1
            else:
                widget = ListItem()
                widget.text = str(menu1[child]['titolo'])
                widget.secondary_text = str(menu1[child]['desc'])
                widget.tertiary_text = str(menu1[child]['prezzo'])
                left_w = LeftLabel()
                left_w.text = '0'
                right_wm = RightMinusWidget()
                right_wm.icon = 'minus'
                right_wp = RightPlusWidget()
                right_wp.icon = 'plus'
                Clock.schedule_once(partial(self.add_widget,right_wm),0.02)
                Clock.schedule_once(partial(self.add_widget,right_wp),0.03)
                Clock.schedule_once(partial(self.add_widget_f,0.04) 
                NoI = NoI + 1

        NoI = 0
        for child in menu2:
            if str(menu2[child]['icon']) == 'cart-off':
                widget = ListItem()
                widget.text = str(menu2[child]['titolo'])
                widget.secondary_text = str(menu2[child]['desc'])
                widget.tertiary_text = str(menu2[child]['prezzo'])
                left_w = LeftLabel()
                left_w.text = '0'
                right_w = IconRightWidget()
                right_w.icon = 'food-off'
                Clock.schedule_once(partial(self.add_widget,LST_CIBO,0.03)
                NoI = NoI + 1
            else:
                widget = ListItem()
                widget.text = str(menu2[child]['titolo'])
                widget.secondary_text = str(menu2[child]['desc'])
                widget.tertiary_text = str(menu2[child]['prezzo'])
                left_w = LeftLabel()
                left_w.text = '0'
                right_wm = RightMinusWidget()
                right_wm.icon = 'minus'
                right_wp = RightPlusWidget()
                right_wp.icon = 'plus'
                Clock.schedule_once(partial(self.add_widget,0.04)
                NoI = NoI + 1

        NoI = 0
        for child in menu3:
            if str(menu3[child]['icon']) == 'cart-off':
                widget = ListItem()
                widget.text = str(menu3[child]['titolo'])
                widget.secondary_text = str(menu3[child]['desc'])
                widget.tertiary_text = str(menu3[child]['prezzo'])
                left_w = LeftLabel()
                left_w.text = '0'
                right_w = IconRightWidget()
                right_w.icon = 'food-off'
                Clock.schedule_once(partial(self.add_widget,LST_BAR,0.03)
                NoI = NoI + 1
            else:
                widget = ListItem()
                widget.text = str(menu3[child]['titolo'])
                widget.secondary_text = str(menu3[child]['desc'])
                widget.tertiary_text = str(menu3[child]['prezzo'])
                left_w = LeftLabel()
                left_w.text = '0'
                right_wm = RightMinusWidget()
                right_wm.icon = 'minus'
                right_wp = RightPlusWidget()
                right_wp.icon = 'plus'
                Clock.schedule_once(partial(self.add_widget,0.04)
                NoI = NoI + 1

变量“menu”是我从服务器收到的字典,例如: {'0': {'titolo': 'campari & prosecco','desc': 'campari soda,prosecco,arancia','prezzo': '2.50 EUR','icon': 'cart'}}|{' 0': {'titolo': 'caffe','desc': 'caffe espresso mokambo','prezzo': '0.90 EUR','icon': 'cart-off'}}|{'0': {'titolo': 'acqua','desc': 'acqua liscia san benedetto 1lt','prezzo': '1.00 EUR','icon': 'cart'}}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)