使用 FragmentTransaction.setCustomAnimations() 在片段中动画视图

Animate View in Fragment with FragmentTransaction.setCustomAnimations()

我一般用FragmentTransaction.setCustomAnimations(int enter, int exit)来指定fragment的进入和返回的过渡动画。据我了解,传递给该方法的动画只能应用于整个片段视图。我可以告诉整个片段 slide/fade 进出等等

有从片段 A 到 B 的事务,是否可以指定动画,以便在替换时,片段 B 中的特定视图被动画化?假设我希望此视图从点 X 移动到 Y,并且我想在传递给 FragmentTransaction.setCustomAnimations(int enter, int exit) 的资源中指定此行为。有没有办法做到这一点?

FragmentTransaction.setCustomAnimations() applies animation to the Window of your Activity. Thus, views that are inside your Fragment cannot be animated. You have to switch to Transition 个动画。