问题描述
所以我创建了2个标签,并对第一个标签进行了动画处理,但是我无法使第二个动画工作,因此我想在具有相同动画属性的标签后立即对label2进行动画处理
Class DemoApp(MDApp):
def build(self,*args):
labels= MDLabel(text = 'Welcome',halign = 'center',theme_text_color ='Custom',text_color = (0,1),font_style ='H4')
labels2 = MDLabel(text='Welcome to Eden',halign='center',theme_text_color='Custom',text_color=(0,font_style='H4')
anim = Animation(opacity=0,duration=0)
anim += Animation(opacity=1,duration=4)
anim += Animation(opacity=0,duration=2)
anim.start(labels)
return labels
解决方法
您可以绑定第一个标签的on_complete
动画方法来开始第二个标签的动画,如下所示:
Class DemoApp(MDApp):
def build(self,*args):
labels= MDLabel(text = 'Welcome',halign = 'center',theme_text_color ='Custom',text_color = (0,1),font_style ='H4')
labels2 = MDLabel(text='Welcome to Eden',halign='center',theme_text_color='Custom',text_color=(0,font_style='H4')
anim = Animation(opacity=0,duration=0)
anim += Animation(opacity=1,duration=4)
anim += Animation(opacity=0,duration=2)
def _cmp(*args):
anim2 = Animation(opacity=0,duration=0)
anim2 += Animation(opacity=1,duration=4)
anim2 += Animation(opacity=0,duration=2)
anim2.start(labels2)
anim.bind(on_complete=_cmp)
anim.start(labels)
return labels