0

I can use FragmentTransaction#setCustomAnimation(int, int) method to define the animations when changing Fragments as described in this answer. However, this approach is limited to animations defined in XML files.

Is there a way to use programmatically defined animations when switching between Fragments?

Vasiliy
  • 16,221
  • 11
  • 71
  • 127
  • Theoretically it should be possible by overriding `onCreateAnimation` to do... something else. You'd have to use a `setCustomAnimation` with a dummy constant to intercept it in the Fragment however. I do not have a sample for this at this time, which is why this is a comment. – EpicPandaForce Oct 21 '19 at 11:13

1 Answers1

0

Looks like there is no such option.

If I'd need to guess, I'd say that the reason is save&restore flow (aka. process death). It's easy to persist IDs of XML resources in Bundle when the app dies and retrieve them later, but it's much more difficult to re-create custom animation objects after the app is re-launched.

Vasiliy
  • 16,221
  • 11
  • 71
  • 127