Custom Animation Object for Transition in Android?

2019-07-13 02:37发布

问题:

I want to override the default activity transition in Android with something a bit fancier. What I want to do can't be done with the XML set that one would typically use, so I can't use overridePendingTransition because it only accepts integer references to XML-based animation resources.

What I'd like to do instead is create my own object that inherits from Animation and overrides the getTransformation and applyTransformation methods to do my own thing. This much I can do, but I can't seem to find a way to tie this new animation object into the transition. Is there a method like overridePendingTransition that accepts an Animation object? Or am I going about this all wrong?

回答1:

Currently the job is done by the WindowManagerService, which calls AnimationUtils.loadAnimation. AnimationUtils only loads animation sets from xml resources, so it's not possible to use a customized Animation object.

Hope someone would propose a patch to AOSP that adds support to customized Animation object...