Home » Android » Is possible to use an Android Animator to animate a DialogFragment entry?

Is possible to use an Android Animator to animate a DialogFragment entry?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have a DialogFragment which I show() when the user clicks a button on my App.

I would like to set an animation to make a Z-axix rotation on the DialogFragment when it launches (i.e. a 3d card flip animation).

I have succesfully used the windowAnimationStyle and the following style to do simple animations (using the View Animation framework) when the DialogFragment is shown:

<style name="windowAnimationCardFlip" parent="@android:style/Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/card_flip_left_in</item>
        <item name="android:windowExitAnimation">@anim/card_flip_left_out</item>
 </style>

The problem is that the View Animation framework is (to the best of my knowledge), quite limited, and the only rotation that I’m able to do (on xml, at least) is a 2D XY rotation (I want a “3D” z axis rotation).

I tried to use the Property Animation framework (specifically an Object Animator, written in XML), but, while I’m able to achieve the effect when loading simple Fragments as described in the official android tutorials, when I try to apply that XML ObjectAnimator to the windowEnterAnimation attribute, nothing happens.

I would like to know, then, what could be happening? Is it possible to use an ObjectAnimator to animate the windowEntry event? If not, are there other solutions?

How to&Answers: