【问题标题】:Fragment animation : difference between setCustomAnimations and setTransitionStyle片段动画:setCustomAnimations 和 setTransitionStyle 的区别
【发布时间】:2012-06-13 21:52:42
【问题描述】:

我想为两个片段之间的过渡制作动画,这要感谢FragmentTransaction.replace()。我想在 XML 文件中指定我的自定义动画。

调用FragmentTransaction.setCustomAnimations()FragmentTransaction.setTransitionStyle()有什么区别?

谢谢。

【问题讨论】:

    标签: android android-fragments android-animation


    【解决方案1】:

    setCustomAnimations(int, int, int, int) 允许您直接指定动画资源。另一方面,如果您使用setTransitionStyle(int),则必须使用FragmentAnimation stylesetTransition(int) 来指定它们。

    值得一提的是,兼容性库会忽略setTransitionStyle(int),所以如果你使用它,你肯定要使用setCustomAnimations(int, int, int, int)

    如需了解更多信息,请查看excellent post about Fragment states and Fragment animations

    【讨论】:

    • MAAAAA 谢谢你的链接!
    • 我在这里补充一点,重要的是你打电话给setCustomAnimations() 之前你打电话给add()replace(),否则它会被忽略。那个无证的东西花了我一些时间。您也可以为不需要动画的参数指定 0。
    • 完美,在 ft.replace 解决我的问题之前要小心使用 ft.setCustomAnimations
    • 自此答案以来,支持库似乎改进了转换支持。 21(2014 年 10 月)和 24.2.0(2016 年 8 月)。 developer.android.com/topic/libraries/support-library/…
    猜你喜欢
    • 1970-01-01
    • 2012-09-26
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 2016-07-14
    • 1970-01-01
    • 2015-03-29
    相关资源
    最近更新 更多