片段过渡动画:从隐藏操作栏的片段到显示操作栏的片段

时间:2018-09-24 18:06:22

标签: android android-fragments animation shared-element-transition

我有两个片段Fragment AFragment BFragment A有一个按钮,将Fragment A替换为Fragment B。同样,Fragment B有一个按钮,它用Fragment A代替。我想在Fragment A中添加按钮的动画,使其扩展到Fragment B,然后将Fragment B收缩至Fragment A的按钮(当`Fragment中的按钮按下)。

我设法用shared elements来做到这一点。我在按钮上添加了transitionName,并在ConstraintLayout中与包含按钮的Fragment B同名。光滑又漂亮!

现在是问题所在:我希望Fragment B隐藏操作栏,而Fragment A显示操作栏,当然,动画也可以流畅地工作。 Fragment B在其onCreate方法中,通过调用getSupportActionBar().hide()隐藏了操作栏,当从Fragment A过渡到Fragment B时,一切看起来都很好。

Fragment A在其onCreate方法中显示了操作栏。当我从Fragment B过渡到Fragment A时,我看到Fragment B并没有线性缩小为按钮。看起来好像在绘制动作栏时,动画意识到必须重新定位按钮,然后您才能看到动画中的跳转。

我尝试了不同的方法:为操作栏设置动画并删除动画,将其显示和隐藏在onCreate以及处理片段替换的活动代码中……

通过显示和隐藏操作栏来处理这种过渡的正确方法是什么?

谢谢Marko

0 个答案:

没有答案