我目前用于打开和关闭按钮的动画只是一个从主按钮出来的子按钮,并使用size_hint进行扩展。该动画只是放大了子布局。我想改为“公开”子布局。我的意思是,不要弄混sub的size_hint,而不是扩展自身,我希望它“展示”自身,从而使动画更加清晰。这是使用相同效果的按钮动画的链接。 https://codemyui.com/button-to-a-list-animation/。 在链接的动画中,底部边框向下并显示下面的列表,与我想要的效果相同。
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics import *
from kivy.animation import Animation
from kivy.lang.builder import Builder
from kivy.uix.behaviors import *
from kivy.properties import *
Builder.load_string("""
<Root>
Button1:
size_hint: 0.2,0.1
pos_hint: {'top':0.9,'center_x':0.5}
canvas:
Color:
rgba: [0.4,0.4,0.4,1]
Rectangle
size: self.size
pos: self.pos
SubLayout:
pos_hint: {'top':1,'center_x':0.5}
canvas:
Color:
rgba: [0.7,0.7,0.7,1]
Rectangle
size: self.size
pos: self.pos
Color:
rgba: [1,1,1,1]
Ellipse:
pos: self.pos
size: self.size
""")
class Root(FloatLayout):
pass
class Button1(ToggleButtonBehavior, FloatLayout):
def __init__(self,**kwargs):
super(Button1,self).__init__(**kwargs)
def on_state(self, *args):
if self.state == 'down':
anim = Animation(pos_hint={'top':0},d=0.2)
anim += Animation(size_hint=(2,2),d=0.2) #: expanding sublayout, how do I unveil instead?
anim.start(self.children[0])
else:
anim = Animation(size_hint=(1,1),d=0.2)
anim += Animation(pos_hint={'top':1},d=0.2)
anim.start(self.children[0])
class SubLayout(FloatLayout):
pass
class TestApp(App):
def build(self):
return Root()
if __name__ == '__main__':
TestApp().run()
如您所见,SubLayout展开,您可以看到内部的椭圆通过按钮展开。我想让边界移开,露出边界下面的内容,同时使椭圆的大小保持不变,这就是“展开”效果。任何想法如何做到这一点将不胜感激。也许与Fbo有关?